开发者

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 p开发者_高级运维urpose 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.


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

:selected => (@category.active? ? 'Yes' : 'No')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜