On Feb 9, 2012, at 8:56 PM, Christopher Jones wrote:

>> That one-liner ought to Just Work.
>> 
>> Walter
> 
> I have my code like this but I just doesn't seem to generate a wishlist 
> :(
> 
> before_filter :set_wishlist, :only => :create
> 
>  def set_wishlist
>    @wishlist = Wishlist.create(params[:wishlist])
>    @wishlist.user = current_user
>    @wishlist.save
>  end
> 

And just to confirm, you are doing this in the user controller, right? What do 
your models look like for wishlist and user then? If you have defined the 
has_many belongs_to relationship, then the one-liner I showed you:

 @wishlist = current_user.wishlists.create(params[:wishlist])

should create the relationship and build and save the wishlist.

Walter

> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to