Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails- nested content_tag

I'm trying to nest content tags into a custom helper, to create something like this:

<div class="field">    <label>A Label</label>    <input class="medium new_value" size="20" type="text" name="value_name" /> </div> 

Note that the input is not associated with a form, it will be saved via javascript.

Here is the helper (it will do more then just display the html):

module InputHelper     def editable_input(label,name)          content_tag :div, :class => "field" do           content_tag :label,label           text_field_tag name,'', :class => 'medium new_value'          end     end end  <%= editable_input 'Year Founded', 'companyStartDate' %> 

However, the label is not displayed when I call the helper, only the input is displayed. If it comment out the text_field_tag, then the label is displayed.

Thanks!

like image 251
christo16 Avatar asked Nov 17 '10 14:11

christo16


1 Answers

You need a + to quick fix :D

module InputHelper   def editable_input(label,name)     content_tag :div, :class => "field" do       content_tag(:label,label) + # Note the + in this line       text_field_tag(name,'', :class => 'medium new_value')     end   end end  <%= editable_input 'Year Founded', 'companyStartDate' %> 

Inside the block of content_tag :div, only the last returned string would be displayed.

like image 182
PeterWong Avatar answered Oct 15 '22 14:10

PeterWong