I have the following code inside a helper in rails:
def custom_options_tag(opts={})
['am', 'pm'].each do |meridian|
["12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11"].each do |time|
if @event.send(opts[:method], opts[:arg]) == time.to_s + meridian
engine = Haml::Engine.new("%option{:value => human_time, :selected => 'selected'}= human_time")
else
engine = Haml::Engine.new("%option{:value => human_time}= human_time")
end
engine.render(Object.new, :human_time => time.to_s + meridian)
end
end
end
My question is…
How can this code be rendered in my view?
It seems there is no way to render haml code that has gone through a loop inside a helper method.
To simplify things I’ve tried to render a paragraph 3 times…
def some_paragraph_helper
3.times do
engine = Haml::Engine.new("%p Some paragraph from helper")
engine.render
end
end
When I call the method…
some_paragraph_helper
…it outputs not the text but simply the number “3” without the paragraph tag. Note that it only shows the number “3” once… as if it was not going through the loop.
Thanks for helping.
LP
You need to return result of
engine.render