我正在尝试返回 redirect_to 并传递额外的参数。这是我的控制器中的内容:
redirect_to(env['omniauth.origin'], :hello => "hello world")
这是正确地重定向到 URL,但 hello 没有被传递。想法?
我正在尝试返回 redirect_to 并传递额外的参数。这是我的控制器中的内容:
redirect_to(env['omniauth.origin'], :hello => "hello world")
这是正确地重定向到 URL,但 hello 没有被传递。想法?
是env['omniauth.origin']字符串吗?如果是这样,我认为这行不通。您可以尝试将参数添加为:
redirect_to(env['omniauth.origin'] + "?hello=helloworld")
或类似的东西。
redirect_to最终调用url_for,如果参数url_for是一个字符串,它只是简单地返回该字符串不变。它忽略任何其他选项。
我建议简单地使用 Rails 的Hash#to_query方法:
redirect_to([env['omniauth.origin'], '?', params.to_query].join)
在您的路线中为其添加路径并将 helloworld 作为参数传递
redirect_to(route_in_file_path('helloworld'))
ApplicationController向类添加函数
class ApplicationController  < ActionController::Base    
  def update_uri(url, opt={})
    URI(url).tap do |u|
      u.query = [u.query, opt.map{ |k, v| "#{k}=#{URI.encode(v)}" }].
                 compact.join("&")
    end
  end
  helper_method :update_uri # expose the controller method as helper
end
现在您可以执行以下操作:
redirect_to update_uri(env['omniauth.origin'], :hello => "Hello World")