N00B Question: How to access methods in a helper?


#1

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


#2

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


#3

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