On Tue, Sep 7, 2010 at 11:02 PM, nobosh <bhellm...@gmail.com> wrote: > Hello, Rails newbie.... > > How can I go From: > > @book = current_user.books.build(params[:book]) > > TO: > > @book = current_user.books.create(params[:book], :instance => > current_user.instance_id) > > > right now I get the following error "wrong number of arguments (2 for > 1)" > > Thanks
I'm assuming that 'instance_id' is an attribute of a Book. In that case, it needs to be part of the Hash you pass to #build or #create. You can do either: > params[:book][:instance_id] = current_user.instance_id > @book = current_user.books.create(params[:book]) or > @book = current_user.books.create(params[:book].merge(:instance_id => current_user.instance_id)) Both assume that params[:book] is non-nil and is a Hash. I'd prefer the first - it's more readable. Adam -- 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-t...@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.