I’m trying to write a helper method to simplify building forms using Bootstrap Twitter. When I try and put a label_tag into the helper method nothing is output. Every other helper_tag method in the function works just not this label_tag. Any ideas as to what I’m doing wrong?
name is a symbol and text is the labels text
Helper Code
def bootstrap_form_text_field(name, text)
content_tag :div, class: "control-group" do
label_tag name, text, class: "control-label"
content_tag :div, class: "controls" do
text_field_tag name
end
end
end
View Code
<%= bootstrap_form_text_field :called_number, "Called Number" %>
Output
<div class="control-group"><div class="controls"><input id="called_number" name="called_number" type="text" /></div></div>
I’m using ruby-1.9.3-p0 and rails 3.2.2 if that helps.
edit:
Seems like only the last tag helper being called is being displayed. I copied the label_tag to just below the text_field_tag and the label was the only thing being displayed.
Try this
I’m not sure if that + will work correctly like that, but it’s a matter of combining the results of all of the tags if you have more than one on each level, you could even combine them in a variable and then return that variable at the end of the current scope.