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.
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>"
This is an old question, but I found this first and had the same trouble as OP. Best solution I found was to use this:
ActionController::Base.helpers.content_tag(:div, nil, class: 'my_div')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With