default_url_options 和 rails 3 [英] default_url_options and rails 3

查看:44
本文介绍了default_url_options 和 rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 ActionController::Base#default_url_options 已被弃用,我想知道如何在 rails3 中设置默认 url 选项.默认 url 选项不是静态的,而是取决于当前请求.

As ActionController::Base#default_url_options is deprecated, I wonder how to set default url options in rails3. The default url options are not static but dependent of the current request.

http://apidock.com/rails/ActionController/Base/default_url_options

谢谢,科林

推荐答案

要为当前请求设置 url 选项,请在您的控制器中使用以下内容:

To set url options for current request use something like this in your controller:

class ApplicationController < ActionController::Base

  def url_options
    { :profile => current_profile }.merge(super)
  end

end

现在,:profile => current_profile 将自动合并到路径/url 参数.

Now, :profile => current_profile will be automerge to path/url parameters.

示例路由:

scope ":profile" do
  resources :comments
end

随便写:

comments_path

如果 current_profile 已将 to_param 设置为 'lucas':

and if current_profile has set to_param to 'lucas':

/lucas/comments

这篇关于default_url_options 和 rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆