On Feb 9, 2012, at 10:43 AM, Christopher Jones wrote:

> Hi,
> 
> I tried the method that I stated in the model:
> 
> def set_wishlist
> @wishlist = Wishlist.new(params[:wishlist])
> end
> 
> But once I created the user it returned an error screen stating:
> 
> NameError in UsersController#create
> 
> undefined local variable or method `params' for #<User:0x4a51a78>
> Rails.root: C:/finalproject

If you tried this in the controller, you would find the params hash available. 
But in the model, there's no such animal. That's what the error message is 
telling you. You could pass that variable back to the model, like this:

def set_wishlist(params)
...
end

and then include the params hash in your method call. But if you want to rely 
on that hash just being there, you could probably put this method in your 
controller and call it from there in your after_create callback.

Walter


> 
> Application Trace | Framework Trace | Full Trace
> 
> app/models/user.rb:21:in `set_wishlist'
> app/controllers/users_controller.rb:35:in `block in create'
> app/controllers/users_controller.rb:34:in `create'
> 
> 
> 
> My usersController create methods looks like the following:
> 
> def create
>  @user = User.new(params[:user])
>  respond_to do |format|
>    if @user.save
>      UserMailer.registration_confirmation(@user).deliver
>      session[:user_id] = @user.id
>      format.html { redirect_to root_url, :notice => "User was 
> successfully created." }
> 
>    else
>      format.html { render :action => "new" }
>      format.xml  { render :xml => @user.errors, :status => 
> :unprocessable_entity }
>    end
>  end
> end
> 

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