Forum: Ruby on Rails N00B Question: How to access methods in a helper?

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.
mariano.kamp (Guest)
on 2005-12-08 22:30
(Received via mailing list)
Hi,

  I always get the following error when trying to access a helper
method.

-->  undefined method `some_helper_method' for
#<BlogController:0x2706fec>

blog_controller.rb:
class BlogController < ApplicationController
  def index
    render(:text => some_helper_method("x"))
  end
end

blog_helper.rb:
module BlogHelper
  def some_helper_method(text)
    text+="!!!!"
  end
end

(Structure came from script/generate controller Blog)

  On a sidebar ... What I was actually trying is to use textilize, but
also
got the same error message. Installing redcloth as gem didn't help,
neither
adding require_gem "RedCloth" to environment.rb.

  ???

  Any idea what I do wrong?

Cheers,
Mariano
technoweenie (Guest)
on 2005-12-08 22:38
(Received via mailing list)
> blog_controller.rb:
> class BlogController < ApplicationController
>   def index
>     render(:text => some_helper_method("x"))
>   end
> end

Helpers are not available in controllers.  Try this instead:

def index
  render :inline => "<%= some_helper_method('x') %>"
end


--
rick
http://techno-weenie.net
skaes (Guest)
on 2005-12-09 07:31
(Received via mailing list)
Rick O. wrote:

>
>def index
>  render :inline => "<%= some_helper_method('x') %>"
>end
>
>
Another possibility is:

def index
  render_text(@template.some_helper_method("x"))
end

More efficient too. But it will not work for helpers that require the
full view context to run.

-- stefan

http://railsexpress.de/blog
This topic is locked and can not be replied to.