I am trying to use the same code that I used in rails 3 for sessions.
def create
user = User.find_by_name(params[:name])
if user && user.authenticate(params[:password])
session[:user_id] = user.id #stores the id in the session
redirect_to user #displays the user/show view
else
flash.now[:error] = "Invalid name/password combination."
render 'new'
end
end
I have adjusted it to
def create
user = User.find_by_username(params[:username])
if user && user.authenticate(params[:password])
session[:user_id] = user.id #stores the id in the session
redirect_to user #displays the user/show view
else
flash.now[:error] = "Invalid name/password combination."
render 'new' #shows the signin page again
end
end
But I am now getting the error:
"SyntaxError in SessionsController#new"
/sessions_controller.rb:5: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n' ...te(params[:password]) session[:user_id] = user.id
I'm sure it is to do with the fact I am using rails 4 now and not 3 and there is some syntax that is not compatible with 4, but I can't seem to work it out.
Aucun commentaire:
Enregistrer un commentaire