Reputation: 10350
Here is a piece of code in edit.html.erb which does not work. The purpose of the code is to fill a form for editing. Collection is used with option of yes and no. How can I set the collection to the current 'active' value with :selected option?
<%= simple_form_for @category do |f| %>
<%= f.input :name, :disabled => true, :required => false %>
<%= f.input :description %>
<%= f.input :active, :collection => ['Yes', 'No'], :selected => f.active %>
<%= f.button :submit %>
<% end %>
The error saying the active is not a method in f.input :active, :collection.
Upvotes: 10
Views: 14806
Reputation: 4807
Assuming the active
attribute for categories is a boolean, try:
:selected => (@category.active? ? 'Yes' : 'No')
Upvotes: 13