Trying to learn ruby on rails following Michael Hartl's tutorial, when I try to go to the registration page in the book I get this:
NoMethodError in UserController#register undefined method `save' for nil:NilClass
here is the code from the user_controller.rb file:
class UserController < ApplicationController
def index
@title = "RailsSpace User Hub"
end
def register
@title = "Register"
if request.post? and params[:user]
@user = User.new(user_params)
end
if @user.save
flash[:notice] = "User #{@user.screen_name} created!"
redirect_to :action => "index"
end
end
private
def user_params
# Add the user attributes that you sent with post (form) to the permit
method.
params.require(:user).permit(:name, :screen_name)
end
end
It's complaining about line 11 where it says: if @user.save I'm just following the tutorial I don't know what's going on.