开发者

Is there a new syntax for `url_for` in rails 3?

开发者 https://www.devze.com 2023-01-14 22:59 出处:网络
In a plugin helper, I have: include Rails.application.routes.url_helpers url_for(:only_path => true, :controller => \'people\', :action => \'new\')

In a plugin helper, I have:

include Rails.application.routes.url_helpers
url_for(:only_path => true, :controller => 'people', :action => 'new')

Note t开发者_运维知识库hat uses the new include syntax, that part works ok. But I get an error:

undefined local variable or method `controller' for #<ActionView::Helpers::InstanceTag:0x311ddf4>

Is there a new way to specify this, like maybe 'controller#action' ? what's the key?


url_for should work as usual, see http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for

I checked it on my console:

ruby-1.9.2-head > include Rails.application.routes.url_helpers
 => Object 

ruby-1.9.2-head > url_for(:only_path => true, :controller => 'admin/providers', :action 
=> 'new')

=> "/admin/providers/new" 

Maybe the error doesn't occur in the url_for because your error messages says ActionView::Helpers::InstanceTag this sounds like you're using some kind of Tag like link_to etc. Did you think about this?

Best regards

Simon

0

精彩评论

暂无评论...
验证码 换一张
取 消