0

I've followed the Railscast for migrating an application to Rails 4 and the transition to Strong Parameters. http://railscasts.com/episodes/415-upgrading-to-rails-4

I have my Create/New methods working fine. But, I'm having problems when I try to update a record. I keep getting the following message:

ArgumentError in CustomersController#update Unknown key: first_name

I've looked at various posts here on Stack Overflow and also generated a new Rails 4 app to verify that I'm doing things correctly. I'm obviously missing something.

Here is my Controller code for the update method:

def update
    @customer = Customer.find(customer_params)

    respond_to do |format|
      if @customer.update(customer_params)
        format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @customer.errors, status: :unprocessable_entity }
      end
    end
  end

Here is where I'm setting up my strong parameters:

private

def set_customer
      @customer = Customer.find(params[:id])
end

def customer_params
  params.require(:customer).permit(:first_name, :middle_initial, :last_name, :address1, :address2, :city, :state, :zip, :phone, :gender, :email, :membership_id, :date_of_birth)
end

Any assistance is greatly appreciated.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Scott S.
  • 749
  • 1
  • 7
  • 26

1 Answers1

5

You don't want to use customer_params in your find statement, you'll want to use the normal find(params[:id]) for that.

Strong Parameters are only used when creating/updating database records. They effectively replace the Rails 3 attr_accessible calls in your models.

Donovan
  • 15,917
  • 4
  • 22
  • 34