开发者

Why does my Rails FormHelper (Formtastic) not display booleans correctly?

I am using Formtastic and I have a simple boolean field. In开发者_StackOverflow my view, I have

        <%= f.input :active, :label => "Enabled?", :as => :select, :include_blank => false, :collection => [ ["Yes", true], ["No", false] ] %><br />

It saves to the database just fine. But when it loads, it always shows the first value ("Yes").

What am I missing? It should default to "No" when the field is false.

Thanks for any tips.

EDIT

When I put the ["No", false] first, it works!

        <%= f.input :active, :label => "Enabled?", :as => :select, :include_blank => false, :collection => [ ["No", false], ["Yes", true] ] %>

Why would that matter?????


Here is a submitted bug/patch on the topic

https://rails.lighthouseapp.com/projects/8994/tickets/5702-options_for_select-do-not-select-boolean-values-correctly

and it is fixed in rails >= v3.0.3


What happens if you remove the :include_blank => false? Is the first option (blank) selected? If so, could the value for the attribute be nil and not false?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜