ruby on rails - Is it possible to bind an attribute to a forms_helper.select in a partial? -


In a rail view, I & lt; Select & gt; Trying to show a drop-down list for several string fields with restricted values.

I'm trying to do this with partial (below), but the current value is & lt; Not being selected in select & gt; List.

  • Is it possible to do partially? if so, how?
  • Is there a better way?

edit.html.erb:

  & lt;% form_for (@my_class) do | F | | & Gt%; & Lt;% = Render: Partial = & gt; "Select",: local => {: Attribute_name = & gt; : Blah, f => F}%> & Lt;% end% & gt;  

_select.html. ARB:

  & lt; P & gt; ... & lt;% = f.label feature_name% & gt; & Lt; Br / & gt; & Lt;% = f.select attribute_name, [: option_a,: option_b,: option_c], {: selected = & gt; Att__name}%> ... & lt; / P & gt;  

I believe that the selected option based on price check, not the name of the attribute .

This may work for you, but I have not tested it:

  <% = f.select attribute_name, [: option_a,: option_b, : Option_c], {: selected = & gt; @ My_class.send (attribute_name)}%>  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -