我正在关注教程:http://visionmasterdesigns.com/tutorial-create-a-login-system-in-ruby-on-rails/ 创建登录页面
当我尝试做这个部分时:
def authenticate
02. #User.new(params[:userform]) will create a new object of User, retrieve values from the form and store it variable @user.
03. @user = User.new(params[:userform])
04. #find records with username,password
05. valid_user = User.find(:first,:conditions => ["user_name = ? and password = ?",@user.user_name, @user.password])
06.
07. #if statement checks whether valid_user exists or not
08. if valid_user
09. #creates a session with username
10. session[:user_id]=valid_user.user_name
11. #redirects the user to our private page.
12. redirect_to :action => 'private'
13. else
14. flash[:notice] = "Invalid User/Password"
15. redirect_to :action=> 'login'
16. end
17.end
并使用正确的用户名和登录名运行它,它告诉我
ActiveRecord :: RecordNotFound in UsersController#私人
无法找到ID = private
的用户
我希望它重定向到private.html.erb页面而不是搜索它!
感谢您的帮助
答案 0 :(得分:3)
我认为你想要render :action => 'private'
而不是重定向。