我有2个视图,两个都有一个编辑按钮。 此按钮重定向到 edit_view 。 如果我在那里提交,重定向应该让我回到我来自的地方。并将id params传回,并获取其中一个视图的URL。
型号:
localhost:3000 / order / list> / order / edit_single_order > 本地主机:3000 /顺序/列表ID = 1
localhost:3000 / order / administrate> / order / edit_single_order > /订单/管理金融
重定向:
def redirect_to_back_or_default_params(default = root_url, *args)
if request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
redirect_to :back, *args
else
redirect_to default, *args
end
end
Controller-redirect:
redirect_to_back_or_default_params administrate_order_path(:provider_id => @cart_item.product.provider.id)
答案 0 :(得分:0)
问题解决了: 我通过store_location
传递了参数控制器/视图:
store_location(params[:provider_id])
Store_location:
def store_location(args=nil)
#test to prevent Url's like order/administrate?id=
if args.nil?
session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
else
session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}?id=#{args}"
end
end
重定向:
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end