Thursday, February 9, 2012

Re: [Rails] Re: Re: Re: Re: Re: Multiple feature creation.

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 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.
>

--
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