Forum: Ruby on Rails Accessing helpers in ApplicationHelper

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C25909d53e693206a9ec8cbf0631092e?d=identicon&s=25 Witold Rugowski (viciu)
on 2007-03-28 15:46
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 Rugowski
http://nhw.pl/wp/ (EN blog)
http://nhw.pl/pl/ (PL blog)
6d57db44c5a4e0721cc7f78cf0ce308a?d=identicon&s=25 Stephen Bartholomew (steveb)
on 2007-03-28 17:05
(Received via mailing list)
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
C25909d53e693206a9ec8cbf0631092e?d=identicon&s=25 Witold Rugowski (viciu)
on 2007-03-28 21:36
Stephen Bartholomew 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 ;-)


--
Witold Rugowski
http://nhw.pl/wp/ (EN blog)
http://nhw.pl/pl/ (PL blog)
This topic is locked and can not be replied to.