DGM
DGM

Reputation: 26979

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

In a plugin helper, I have:

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

Note that 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?

Upvotes: 2

Views: 4438

Answers (1)

sled
sled

Reputation: 14625

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

Upvotes: 7

Related Questions