How do I insert variable values into HTML tags in ERB templates?
I have a partial like:
<% office.map do |o| %>
&l开发者_运维问答t;input id='city' name='company[company_office][0][city]' value=.... type='text' />
<% end %>
How can I insert a value like o.office
into an attribute? value="#{o.office}"
does not work.
<% office.map do |o| %>
<input id='city' name='company[company_office][0][city]' value='<%= o.office %>' type='text' />
<% end %>
or you could use the form helpers for that
Use embedded ruby(erb) tags,
<%= o.office %>
The only time you'd use #{o.office}
is when you're not using erb. In a helper method for example and you want to use your ruby in a string. But when you're in an html.erb
file, you have to use the erb tags.
精彩评论