I have a migration that uses a boolean and generates a checkbox in its view. However, no matter what I click, the value stored in the database does not change.
My migration is as follows:
def self.up
create_table :blogposts do |t|
t.string :title
t.text :body
t.boolean :allow_comments, :default => false
t.references :author
t.references :lasteditor
t.timestamps
end
end
My view is as follows:
<% semantic_form_for([:controlpanel, @blogpost]) do |form| %>
<%= form.error_messages %>
<% form.inputs do %>
<%= form.input :title %>
<%= form.input :body %>
<%= form.input :allow_comments %>
<% end %>
<%= form.buttons %>
Generates the following HTML:
<li class="boolean required" id="blogpost_allow_comments_input">
<label for="blogpost_allow_comments">
<input id="blogpost_allow_comments" name="blogpost[allow_comments]" type="checkbox" value="1" />
<input name="blogpost[allow_comments]" type="hidden" value="0" />Allow comments
<abbr title="required">*</abbr>
</label>
</li>
The controller is only the default created by the scaffold.
If I set the default value in migration, this value is always stored in the database. If I did not set a default value, it is always NULL.
Can someone suggest a solution, a suggestion on what could go wrong?
Any advice is appreciated.
Thanks.