I have an Item model:
class Item < ActiveRecord::Base
attr_accessible :author, :title
end
And a Book model:
class Book < ActiveRecord::Base
attr_accessible :item_id, :plot
belongs_to_ :item
end
I want to be able to create a book by using
Book.new(:title=>"Title", :author=>"Author", :plot=>"BlaBla")
Book.save
And it will create an Item with the title and author, and also create a Book with the created Item ID.
How is it possible?
You need to use
:after_createcallback and virtual_attributes as follows.In you book model write this