Rails form helpers: how to add an element to a collection?
Posted
by Laran Evans
on Stack Overflow
See other posts from Stack Overflow
or by Laran Evans
Published on 2009-07-14T19:06:53Z
Indexed on
2010/05/10
18:04 UTC
Read the original article
Hit count: 220
ruby-on-rails
I have a keychain object. keychain has_many credentials.
I'm trying to write the view code to add a new credential to a keychain. This is the code I have:
<% form_for(@keychain) do |f| %> <tr> <td><%= f.select "credentials[]", current_account.services.collect{ |s| [s.friendly_name, s.id] } %></td> <td><%= f.text_field 'credentials', :username %></td> <td><%= f.password_field 'credentials', :password %></td> </tr> <% end %>
But it fails with this message:
NoMethodError in Keychains#new Showing app/views/keychains/_keychain_form.html.erb where line #32 raised: undefined method `credentials[]' for #
What am I doing wrong?
© Stack Overflow or respective owner