Make all helper ActionViewer methods available in the module

I use ruby ​​on reiki 3. I have a model called Content. Inside the controller, I extract some variables and pass them to the viewer. In the viewer, I would like to use my own functions so that I don't have too much logic and code in the viewer. I defined these functions in the module ContentsHelper.

My functions defined in the ContentsHelper module use the auxiliary functions of the ActionViewer, however they are not available in the ContentHelper module. I get, for example, an error NoMethodError: undefined method content_tag' for #<Content:0x1025b9458>.

How can I make all the auxiliary functions of ActionViewer available?

Newbie.

after Tim’s suggestion:

module ContentsHelper
include ActionView::Helpers
  def bla
    content_tag(:h2, self.title)        
end

I can run the bla method as Content.blain the console. It's fine!

content_tag image_tag, :

NoMethodError: undefined method `config'
from /Users/sonat/.rvm/gems/ruby-1.8.7-p334/gems/activemodel-3.0.0/lib/active_model/attribute_methods.rb:364:in `method_missing'
from /Users/sonat/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-3.0.0/lib/active_record/attribute_methods.rb:46:in `method_missing'
from /Users/sonat/.rvm/gems/ruby-1.8.7-p334/gems/activerecord-3.0.0/lib/active_record/attribute_methods.rb:44:in `send'

, , image_tag, "-". , , , .

+3
2

, - , , . , .

, , , . , .

, :

//contents_helper.rb

module ContentsHelper
  def foo
    content_tag :p, "Foo"
  end
end

///index.html.erb

<h1>Listing Contents</h1>

<%= foo %>

HTML / URL

<h1>Listing Contents</h1>

<p>Foo</p>

, .

+2

content_tag:

?

module ContentsHelper
 include ActionView::Helpers
end

IMAGE_TAG:

, , , #path_to_image(image).

Gist , , :

https://gist.github.com/1015333

forNoNameNo.rb( .)

, image_tag.


:

, , Rails. , ; , , , - . .

-, , Presenter. ( . rbates)

, , .

textmate:

    mate `gem which actionpack`../action_view

Terminal.app . / , , gem which actionpack .

+2

All Articles