Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set current value in collection in simple_form

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.

like image 732
user938363 Avatar asked Sep 18 '11 23:09

user938363


1 Answers

Assuming the active attribute for categories is a boolean, try:

:selected => (@category.active? ? 'Yes' : 'No')
like image 123
James Avatar answered Nov 04 '22 20:11

James