复选框助手没有更新数据库Ruby on rails上的值

时间:2017-06-15 08:01:03

标签: html ruby-on-rails ruby database checkbox

复选框帮助程序不会在数据库中更新或插入布尔值。 标签有许多属性,默认值为false,选中复选框后应该变为true。但是只更新了email属性。

labelscontroller

    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.html.erb

<%= 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 %>

PARAMS

developement.rb server logs

创建提交后的数据库值

rails console output of label when i ckecked both email and intro

0 个答案:

没有答案