开发者

Rails redirect issue - Hartl's Rails Tutorial 10.2.3

开发者 https://www.devze.com 2023-02-15 00:24 出处:网络
I\'m a complete noob working through Michael Hartl\'s (awesome) Rails tutorials, and have an issue with the friendly redirect in Ch.10.2.3.The purpose is to try to store the location, redirect to the

I'm a complete noob working through Michael Hartl's (awesome) Rails tutorials, and have an issue with the friendly redirect in Ch.10.2.3. The purpose is to try to store the location, redirect to the sign in page, then redirect back to the 开发者_如何学Gooriginal intended destination when sign-in is complete. My problem is that it simply renders the standard user profile page after signing in/creating a session, rather than redirecting.

I have this in the sessions_controller:

def create
  user = User.authenticate(params[:session][:email],
                           params[:session][:password])
  if user.nil?
    flash.now[:error] = "Invalid email/password combination."
    @title = "Sign in"
    render 'new'
  else
    sign_in user
    redirect_back_or user
  end
end

And this in sessions_helper:

def authenticate
  deny_access unless signed_in?
end

def deny_access
  store_location
  redirect_to signin_path, :notice => "Please sign in to access this page."
end    

def redirect_back_or(default)
  redirect_to(session[:return_to] || default)
  clear_return_to
end

private
  def store_location
    session[:return_to] = request.fullpath
  end

 def clear_return_to
   session[:return_to] = nil
 end

I'm sure I've yet again made a stupid, simple mistake but I can't find it.. help?


The code is available here: https://github.com/railstutorial
Consider making a new git branch (or new project) for yourself that uses just this repository's code. Then you will have a working local version for comparison when things go wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消