单击new_photo_path链接会重定向到login_path ..之后我怎么回到那里?

时间:2016-12-22 22:58:36

标签: ruby-on-rails

class PhotosController < ApplicationController
  before_action :logged_in_user, only: [:new, :create] 
end

class ApplicationController
  def logged_in_user
    unless logged_in?
      store_location
      flash[:danger] = "Please log in."
      redirect_to login_url
    end
  end
end

module SessionHelper 
  def store_location 
   session[:forwarding_url] = request.url if request.get?
  end

  def redirect_back_or(default)
    redirect_to(session[:forwarding_url] || default)
    session.delete(:forwarding_url)
  end
end

class SessionsController 
  def new
    ...
    redirect_back_or(default)
  end
end

在我们访问example.com/photos/new之前,我们必须登录。

但是,登录后,它会将我重定向回login_path。我希望将其重定向到new_photo_path

为什么request.url不是example.com/photos/new

1 个答案:

答案 0 :(得分:0)

SessionsController有错误:

redirect_back_or(default)应为redirect_back_or user