Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

private method `update' called for #<Customer

Whenever I try to do an update on my Customer class, I keep receiving that the a private method 'update' was called.

Application trace: app/controllers/customers_controller.rb:46:in `update'

So, in the code it's in this function:

 43 def update
     44   @customer = Customer.find(params[:id])
     45 
     46   if @customer.update(customer_params)
     47     redirect_to @customer
     48   else
     49     render 'edit'
     50   end
     51 end

So, I assume this issue is occurring within my Customer Model, which is:

class Customer < ActiveRecord::Base
       include ActiveModel::ForbiddenAttributesProtection
   attr_accessible :name, :web_address, :notes
        belongs_to :location
        validates :name, presence: true,
                        length: { minimum: 5 }
end

And then in the view:

  <%= form_for :customer, url: customer_path(@customer), method: :put do |f| %>
<div class="well center col-sm-10">
        <legend> Customer: </legend>
        <span class="row">
        <div class = "form-group col-sm-5">
                <%= f.label :name %><br />
                <%= f.text_field :name %>
        </div>

        <div class = "form-group col-sm-5">
                <%= f.label :web_address %> <br />
                <%= f.text_field :web_address %>
        </div>
        </span>
        <span class="row">
        <div class = "form-group col-sm-5">
                <%= f.label :notes %> <br />
                <%= f.text_field :notes %>
        </div>

        </span>

        <%= f.submit %>
<% end %>

I never defined a private function called update, and I'm not really sure where to begin debugging this.

like image 981
Jeff Avatar asked Dec 02 '22 15:12

Jeff


1 Answers

You should use update_attributes, for Rails versions lesser than 4.

Persistence#update was private prior to Rails4

like image 128
Santhosh Avatar answered Dec 06 '22 17:12

Santhosh