I have a Book resource that belongs both to a User and to an Isbn.
What is the recommended way of building a new Book record in this type
of situation?

class Book < ActiveRecord::Base
  belongs_to :user
  belongs_to :isbn
end

Currently I'm doing the following:

@isbn = Isbn.find(...)
book = @isbn.books.build(...)
book.user_id = @user.id
book.save

Is this the way it's supposed to be done?  I know that it's preferred
to interact with dependent resources through their associations. So
adding the user_id manually seems a bit clunky to me.  But I'm not
sure how else to do it!

Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to