当我单击登录链接时,它应该检查有效的用户名和密码并在登录部分页面上显示消息,我在颜色框中将其作为弹出窗口调用,但我无法显示错误消息。
这是我的登录控制器:
def login
if request.post?
@user = User.new(params[:user])
user=User.authenticate(params[:username], params[:password])
if user.nil?
flash[:error] = 'Login unsuccessful'
redirect_to :back
else
flash[:notice] = 'Login successful'
session[:user] = user.id
redirect_to :controller=>'users', :action => 'show',:username=>user.username
end
end
end
用户.rb:
def self.authenticate(username, pass)
user = find(:first, :conditions=>["username = ?", username])
return nil if user.nil?
return user if User.hash_password(pass) == user.password && username == user.username
nil
end
在我的视图page_sign_in.html.erb
页面中
<%= form_for @user, :url=>{:controller=>"logins",:action=>"login"},:remote=>true,:html=>{ :onSubmit => "return checkSignupValidation()",:id=>"signin_form", :multipart=>true} do |f| %>
@user
给出错误:undefined method
Nilclass`的model_name'