aisflat439
aisflat439

Reputation: 975

Form parameters unpermitted by in rails app

I have a controller for Walkers with the following action:

def update
    if !current_user
        redirect_to "/walkers"
    end
    walker = Walker.find(params[:id])
    walker.update(walker_params)
    walker.save
    redirect_to admin_path
end

There is also a private method:

    def walker_params
        params.require(:walker).permit(:id, :fname, :lname, :role, :active, :role, :avatar)
    end

In my resources I have:

resources :walkers

Then I have a form with the following erb.

    <%= form_for :walker, url: "/walkers/#{w.id}", method: "put" do |f| %>
      <%= f.hidden_field active: false %>
      <%= f.submit "Deactivate", class: "font-color-warning mdl-button" %>
    <% end %>

My rails server gives me the following error:

Unpermitted parameter: {:active=>false}

The parameters being sent are:

Parameters: {"utf8"=>"✓",
"authenticity_token"=>"7vkuiaZG32x0EPr9IR9VvgURTQ7uniZH/7IPfMYdvb3AIGq8Psd+o9ykfs6qMKcozXYm08BKJ0/M3s5Q2DwiGg==", 
"walker"=>{"{:active=>false}"=>""}, 
"commit"=>"Deactivate", 
"id"=>"1"}

My expectation was that I was putting false on the :active parameter of the walker object found at PUT 'walkers/w.id'. My parameters show that my expectation is not correct.

I would like a solution to my problem. Ideally some understanding of why my parameters are being sent with walker"=>{"{:active=>false}"=>""} when my goal is submit parameters with walker"=>{:active=>false}.

I don't have an @walker object to reference because I'm looping through with |w|.

Upvotes: 0

Views: 23

Answers (1)

Zzz
Zzz

Reputation: 1703

change

<%= f.hidden_field active: false %>

to

 <%= f.hidden_field :active, value: false %>

Upvotes: 1

Related Questions