views:

959

answers:

3
+1  A: 

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
Thanks. I have implemented that - thank you. However, I am still having trouble passing a variable to the warning. I wonder if you can help me understand why? (I will paste it below)
The Pied Pipes
+1  A: 

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

The Pied Pipes
+1  A: 

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
The Pied Pipes