views:

86

answers:

1

Hi all,

my problem: I want to create a class TitlePanel in my lib folder that class uses the content_tag method but I can't figure out how to load it. I have tried all require 'xxx' that I could think of and it keeps giving me error messages that it can't find the required file.

Basically, what I am trying to do is create a helper that generates html, but I have to pass thru a class to store some value first. Ex of what I am trying to do:

title = TitlePanel.new("this is my title")
title.add_panel "help" do
  content_tag :div, "this is the help section..."
end
title.add_panel "search" do
   content_tag :div, "this is the search section..."
end

title.to_s

the output being all the required HTML to make this work.

A: 

Give this a shot. If you include TagHelper in at the top of your file in your lib directory, it should work. Here's an example:

class MyLib
  include ActionView::Helpers::TagHelper

  def foo(x)
    content_tag :div, x
  end
end


>> MyLib.new.foo "bar"
=> "<div>bar</div>"
Jim Jones
Alain
improved formating but removed the .to_s method - crap, formating does not work for comments ?
Alain
I'm not sure what's going on in your code sample. But, if you just want to use the content_tag method within module in your lib directory, then you should be able to just add this bit to the top of your file: include ActionView::Helpers::TagHelper
Jim Jones
I did it. But I am still getting the "undefined method `capture' for #<TitlePanel:0x1036ca198>" exception. Isnt requiring TagHelper supposed to get all of its dependencies?
Alain
Here is a pastie of the full code that isnt workinghttp://pastie.org/992668
Alain
Is it possible that when I yield the block that is passed to add_pannel, the block does not have access to the scope where content_tag is defined?But even if this is the answer, it does not explain why I am getting the undefined method 'capture for ...' exception.
Alain