jeudi 15 juin 2017

check box helper not updating value in database Ruby on rails

the checkbox helper isn't updating or inserting boolean values in the database. A label has many attributes with values false as default and should become true when the checkbox is checked.but only the email attribute is being updated.

labelscontroller

    def new 
    @label = current_user.labels.build
end

def create
    puts params.to_s
    puts "====================="
    @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,:works,:phones,:education,:primary_phone_no,:alternate1_phone_no,
:alternate2_phone_no,
:home_phone_no,
:work_phone_no,
:Facebook,
:LinkedIn,
:Twitter,
:GitHub,
:Youtube,
:Instagram,
:Pintrest,
:Quora,
:tumblr,
:Own_blog_webiste,
:AngelList,
:Crunchbase,
:GoodReads,
:Medium,
:Reddit,
:SoundCloud,
:Vine,
:Vimeo,
:alternate_email,
:work_email,
:Whatsapp,
:Hike,
:Snapchat,
:messenger)
end

label/_form.html.erb

<%= form_for @label, :html => { :class => "form-horizontal label" ,multipart: true} do |f| %>

  <% if @label.errors.any? %>
    <div id="error_expl" class="panel panel-danger">
      <div class="panel-heading">
        <h3 class="panel-title"><%= pluralize(@label.errors.count, "error") %> prohibited this label from being saved:</h3>
      </div>
      <div class="panel-body">
        <ul>
        <% @label.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
        </ul>
      </div>
    </div>
  <% end %>

  <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", style="color: black;">
    <%= f.label :avatar, :class => 'control-label col-lg-2' %>
    <div class="col-lg-10">
      <%= f.check_box :avatar %>
    </div>
    <%=f.error_span(:avatar) %>
  </div>
  <div class="form-group", style="color: black;">
    <%= f.label :avatar, :class => 'control-label col-lg-2' %>
    <div class="col-lg-10">
      <%= f.check_box :avatar %>
    </div>
    <%=f.error_span(:avatar) %>
  </div>
  <div class="form-group", style="color: black;">
    <%= f.label :works, :class => 'control-label col-lg-2' %>
    <div class="col-lg-10">
      <%= f.check_box :works %>
    </div>
    <%=f.error_span(:works) %>
  </div>

  <div class="form-group", style="color: black;">
    <%= f.label :education, :class => 'control-label col-lg-2' %>
    <div class="col-lg-10">
      <%= f.check_box :education %>
    </div>
    <%=f.error_span(:education) %>
  </div>


 <div class="form-group", style="color: black;">

        <%= f.label :primary_phone_no, autofocus: true %>
        <%= f.check_box :primary_phone_no %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :alternate1_phone_no, autofocus: true %>
        <%= f.check_box :alternate1_phone_no %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :alternate2_phone_no, autofocus: true %>
        <%= f.check_box :alternate2_phone_no %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :home_phone_no, autofocus: true %>
        <%= f.check_box :home_phone_no %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :work_phone_no, autofocus: true %>
        <%= f.check_box :work_phone_no %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Facebook, autofocus: true %>
        <%= f.check_box :Facebook %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :LinkedIn, autofocus: true %>
        <%= f.check_box :LinkedIn %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Twitter, autofocus: true %>
        <%= f.check_box :Twitter %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :GitHub, autofocus: true %>
        <%= f.check_box :GitHub %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Youtube, autofocus: true %>
        <%= f.check_box :Youtube %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Instagram, autofocus: true %>
        <%= f.check_box :Instagram %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Pintrest, autofocus: true %>
        <%= f.check_box :Pintrest %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Quora, autofocus: true %>
        <%= f.check_box :Quora %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :tumblr, autofocus: true %>
        <%= f.check_box :tumblr %>

            <span></span>
          </div>

<div class="form-group", style="color: black;">

        <%= f.label :Own_blog_webiste, autofocus: true %>
        <%= f.check_box :Own_blog_webiste %>

            <span></span>
          </div>
<div class="form-group", style="color: black;">

        <%= f.label :AngelList, autofocus: true %>
        <%= f.check_box :AngelList %>

            <span></span>
          </div>
          <div class="form-group", style="color: black;">

        <%= f.label :Crunchbase, autofocus: true %>
        <%= f.check_box :Crunchbase %>

            <span></span>
          </div>


          <div class="form-group", style="color: black;">

        <%= f.label :GoodReads, autofocus: true %>
        <%= f.check_box :GoodReads %>

            <span></span>
          </div>


          <div class="form-group", style="color: black;">

        <%= f.label :Medium, autofocus: true %>
        <%= f.check_box :Medium %>

            <span></span>
          </div>

          <div class="form-group", style="color: black;">

        <%= f.label :Reddit, autofocus: true %>
        <%= f.check_box :Reddit %>

            <span></span>
          </div>

          <div class="form-group", style="color: black;">

        <%= f.label :SoundCloud, autofocus: true %>
        <%= f.check_box :SoundCloud %>

            <span></span>
          </div>

          <div class="form-group", style="color: black;">

        <%= f.label :Vine, autofocus: true %>
        <%= f.check_box :Vine %>

            <span></span>
          </div>

          <div class="form-group", style="color: black;">

        <%= f.label :Vimeo, autofocus: true %>
        <%= f.check_box :Vimeo %>

            <span></span>
          </div>

          <div class="form-group", style="color: black;">

        <%= f.label :alternate_email, autofocus: true %>
        <%= f.check_box :alternate_email %>

            <span></span>
          </div>
  <div class="form-group", style="color: black;">

        <%= f.label :work_email, autofocus: true %>
        <%= f.check_box :work_email %>

            <span></span>
          </div>
            <div class="form-group", style="color: black;">

        <%= f.label :Whatsapp, autofocus: true %>
        <%= f.check_box :Whatsapp %>

            <span></span>
          </div>
            <div class="form-group", style="color: black;">

        <%= f.label :Hike, autofocus: true %>
        <%= f.check_box :Hike %>

            <span></span>
          </div>
            <div class="form-group", style="color: black;">

        <%= f.label :Snapchat, autofocus: true %>
        <%= f.check_box :Snapchat %>

            <span></span>
          </div>


<div class="form-group", style="color: black;">

        <%= f.label :messenger, autofocus: true %>
        <%= f.check_box :messenger %>

            <span></span>
          </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

database values after the create commit

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




Aucun commentaire:

Enregistrer un commentaire