views:

21

answers:

1

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?

A: 

Hi,

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

sled
yes, I'm in a form helper, and in an instance tag... I had to make a private method: def controller ; @controller ; end
DGM
I don't get why ruby says you're trying to access a variable/method called controller. Because the only occurrence of the word "controller" in your snippet is a symbol.
sled
url_for internally calls a method on a controller class. In the case of a view plugin, it does not know what controller to call, so I had to set up a private function to set it up.
DGM