Tuesday, September 6, 2011

[Rails] accepts_nested_attributes_for issue

Hello,

I am using accepts_nested_attributes_for for saving the records.

let say I have a model

class User < AR::Base

 has_many :books
 accepts_nested_attributes_for :books

end

class Book < AR::Base
  belongs_to :user
end

Now the params value I am getting is

user={:id => 123, books_attributes={:name => "test"}}

and in my books controller

def create
user = @user.update_attributes(params[:user])
@book = ????
end

Every thing is working as expected but my requirement is that the book which is saved I need to know the ID.

How do I find the books ID.

Thanks
Abhis


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate