You need to call @template.content_tag
. The code you have there is just calling self.content_tag, which obviously doesn't do anything.
Chuck
2009-01-06 16:46:05
You need to call @template.content_tag
. The code you have there is just calling self.content_tag, which obviously doesn't do anything.
This is what I changed the helper method to to try to include a warning label:
def self.create_tagged_field(method_name)
define_method(method_name) do |label, *args|
@template.content_tag("p",
@template.content_tag("label" , labels.to_s.humanize+(@template.content_tag("span", args[:warning]) unless !args[:warning]), :for => "#{@object_name}_#{label}") +
super)
end
end
however, I am not sure how to get at a 'warning' variable or pass it in. What I would like to do is:
<%= form.text_field :name, :warning => "dont do that"] %>
However I am stuck, getting this message:
Symbol as array index
How can I access the warning in the helper method?
TIA
Just wanted to post the final solution, more for pride than anything else. Noob... :0
def self.create_tagged_field(method_name)
define_method(method_name) do |label, *args|
# accepts the warning hash from text_field helper
if (args.first.instance_of? Hash) && (args.first.keys.include? :warning)
warning = args.first[:warning]
end
@template.content_tag("label" , label.to_s.humanize+(@template.content_tag("span", warning, :class =>'small')),
:for => "#{@object_name}_#{label}") +
super
end
end