[英]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.