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
?
答案 0 :(得分:0)
SessionsController
有错误:
redirect_back_or(default)
应为redirect_back_or user