Accessing helpers in ApplicationHelper

Hi!

I want to write custom helper, accessible for all views and I want to
use other helpers like form_remote_tag.

I tried first to move .rhtml template code and parse it with ERB:

module ApplicationHelper
def search_box
str = %|
<%= form_remote_tag(:url => {:controller => :search, :action =>
‘search’},
:update => ‘search_results’) do %>
blah blah
<% end %>
|
return ERB.new(str).run
end

But I’ve got ActionView::TemplateError (undefined method
`form_remote_tag’ for main:Object) after I’ve used search_box helper in
my view.

Adding include ActionView::Helpers::FormTagHelper to ERB string nor
ApplicationHelper does not help.

How I should use helpers in this case?


Witold R.
nhw.pl (EN blog)
NetManiac (PL blog)

I would probably use a partial for this as this doesn’t seem abstract
enough to be a helper. Will you use this form differently in more
than one place?

To answer you’re exact question, I’m not sure that remote_form_tag is
in FormTagHelper - it’s in PrototypeHelper. However, I would
seriously consider using a partial as this helper could get real
messy, real fast.

If you really do need to use a helper, I’d suggest having a look at
the source code for the tag helpers and see how it’s handled by Rails.

Steve

Stephen B. wrote:

I would probably use a partial for this as this doesn’t seem abstract
enough to be a helper. Will you use this form differently in more
than one place?
Well maybe this time I can use partial, but I think using partials could
also become messy (in my case), since with them I have to stick to
variable names. In search form this will be no problem, but in others
could be. Anyway, now I wonder how to use Rails helpers in custom helper
;))

To answer you’re exact question, I’m not sure that remote_form_tag is
in FormTagHelper - it’s in PrototypeHelper. However, I would
seriously consider using a partial as this helper could get real
messy, real fast.
Yes, exactly ProtypeHelper. I have tested with this include :wink:


Witold R.
nhw.pl (EN blog)
NetManiac (PL blog)