samedi 2 mai 2015

collection_check_boxes returning an extra paramater

I'm trying to make a checkbox form in rails using collection_check_boxes.

In the View I have the below...

  <%= f.collection_check_boxes :need1, Skill.all , :name, :name, checked: Skill.all.map(&:id)  do |b| %>
<%= b.check_box %>
      <%= b.label %>
  <% end %>

  <%= f.submit "next", class: "btn btn-primary btn-lg" %>

In the controller I think it is using the update method...

def update
@user = User.find(params[:id])

  if @account.update(account_params)
    @user.account_completed = true
    @user.save

    @account.completed = true
    @account.save
    redirect_to @account, notice: 'Thank you for updating your account. Keep being awesome.'
  else
    render :edit
  end
  end

Our account params "permit" for :need1

In the console we are getting an extra parameter when it tries to update Account.

Started PATCH "/accounts/1" for 127.0.0.1 at 2015-05-02 12:42:26 -0600
Processing by AccountsController#update as HTML
   Parameters: {"utf8"=>"✓", "authenticity_token"=>"aI/JssjLZUJRmQNP52hoz89scEjJ8kcp94SR3y6XbAg=", "account"=>{"need1"=>["Logo Design", ""]}, "commit"=>"next", "id"=>"1"}
   Account Load (0.1ms)  SELECT  "accounts".* FROM "accounts"  WHERE "accounts"."id" = ? LIMIT 1  [["id", 1]]
    User Load (0.2ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
    User Load (0.3ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  Unpermitted parameters: need1

The specific goal is to get Need 1 saved in the Account table. Any advice is appreciated!




Aucun commentaire:

Enregistrer un commentaire