Pergunta

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 %>
Foi útil?

Solução

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.

Outras dicas

Something like:

<% for i in 0..2 %>
  <%=f.input "name#{i}".to_sym %>
  <%=f.input "email#{i}".to_sym %>
<% end %>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top