質問

I need to make a form for a team which consists of 3 members.
I have my model setup as:

field :name1,:name2,:name3   
field :email1,:email2,:email3  

i don't want to write 3 forms in views. How can I dynamically create the symbols which simple_form requires? Some thing like:

<% for i in 0..2 %>
  <%=f.input :name+i %>
  <%=f.input :email+i %>
<% end %>
役に立ちましたか?

解決

You are missing the intern method on strings.

Do it like this:

<% for i in 0..2 %>
  <%=f.input "name#{i}".intern %>
  <%=f.input "email#{i}".intern %>
<% end %>

You can also use the to_sym method.

他のヒント

Something like:

<% for i in 0..2 %>
  <%=f.input "name#{i}".to_sym %>
  <%=f.input "email#{i}".to_sym %>
<% end %>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top