我有一个清醒器,通过在分叉进程中打开URL来重新加热缓存。对于那些URL的主机来说,这很容易,但我希望它根据环境动态地改变。

我知道我可以为此设置全局/环境变量,但我真的很想使用命名的路线。有没有办法来做这个?

(我应该澄清一下,我试过只需将命名的路线放在那里,但它们不会在运行时解决。)

有帮助吗?

解决方案

The closest I found is:

Rails.application.routes.named_routes.get(:user).defaults

Which retrieves:

{:action=>"show", :controller=>"users"}

But you should merge it with your params:

Rails.application.routes.named_routes.get(:user).defaults.merge({:id => 1})

Result:

{:action=>"show", :controller=>"users", :id=>1}

Edit:

Simply add

include Rails.application.routes.url_helpers 

to your class

其他提示

I fixed this in the current Rails 3.2 beta:

https://github.com/rails/rails/pull/3876

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top