On Feb 9, 2012, at 2:34 PM, Christopher Jones wrote:

> Hey Walter,
> 
> I have the following in my userController
> 
> after_filter :set_wishlist, :only => :create
> 
>  def set_wishlist
>    @wishlist = Wishlist.new(params[:wishlist])
>    @wishlist.user = current_user
>  end
> 
> It goes ahead but doesn't actually create a wishlist for the user. I 
> checked in the server log and it seems to just be searching for any 
> wishlist matching this user which it obviously wont find because it 
> hasn't been created.
> 
> Any suggestions?

Try adding @wishlist.save to the end.

Actually, maybe structure it so you are adding a member to the 
current_user.wishlists collection. If you do that, and you do this in a 
before_save filter, then the wishlist will be saved along with the user. Read 
the Rails guides about associations and auto-save. I know there's something in 
there that covers this.

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

That one-liner ought to Just Work™.

Walter

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