[英]redirect to not current page
我有一个在rails 4中带有重定向的问题。我需要重定向到在特定情况下指定的页面。 向后重定向不起作用,因为我需要重定向的页面不是上一页,并且仅在用户单击链接时才需要重定向到该页面。 代码:查看用户单击的位置:
<li >
<%= link_to new_admin_wine_path do %>
<span>
Cadastrar um novo vinho
</span>
<% end %>
</li>
单击该链接时需要重定向到的页面:new_admin_wine_path
控制器:
def store_location
return unless request.get?
if (request.path != new_user_session_path &&
request.path != new_user_registration_path &&
request.path != new_user_password_path &&
request.path != edit_user_password_path &&
request.path != "/:locale/users/confirmation(" &&
request.path != destroy_user_session_path &&
!request.xhr?) # don't store ajax calls
session[:previous_url] = request.fullpath
end
end
def after_sign_in_path_for(resource)
session[:previous_url] || root_path
end
您应该查看过滤器 。 基本上,您将要构造控制器:
class someController < ActionController::Base
after_filter :redirect_method, only: [:whatever, :actions, :you, :want]
def store_location
return unless request.get?
if (request.path != new_user_session_path &&
request.path != new_user_registration_path &&
request.path != new_user_password_path &&
request.path != edit_user_password_path &&
request.path != "/:locale/users/confirmation(" &&
request.path != destroy_user_session_path &&
!request.xhr?) # don't store ajax calls
session[:previous_url] = request.fullpath
end
end
def after_sign_in_path_for(resource)
session[:previous_url] || root_path
end
def redirect_method
redirect_to root_path (or whevever you want to send them)
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.