复选框帮助程序不会在数据库中更新或插入布尔值。 标签有许多属性,默认值为false,选中复选框后应该变为true。但是只更新了email属性。
def new
@label = current_user.labels.build
end
def create
@label = current_user.labels.build(label_params)
if @label.save
redirect_to @label
else
render 'new'
end
end
def labels_params
params.require(:label).permit(:name,:email,:avatar,:nick,:intro)
end
<%= form_for @label, :html => { :class => "form-horizontal label" ,multipart: true} do |f| %>
<div class="form-group", style="color: black;">
<%= f.label :name, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= f.text_field :name, :class => 'form-control' %>
</div>
<%=f.error_span(:name) %>
</div> <div class="form-group", style="color: black;">
<%= f.label :email, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= f.check_box :email %>
</div>
<%=f.error_span(:email) %>
</div>
<div class="form-group", style="color: black;">
<%= f.label :intro, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= f.check_box :intro, checked: false %>
</div>
<%=f.error_span(:intro) %>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
labels_path, :class => 'btn btn-default' %>
</div>
</div>
<% end %>
rails console output of label when i ckecked both email and intro