每当我尝试对Customer类进行更新时,都会不断收到调用私有方法“ update”的消息。
应用程序跟踪: app/controllers/customers_controller.rb:46:in `update'
因此,在代码中该函数位于:
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
因此,我认为此问题是在我的客户模型中发生的,即:
class Customer < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
attr_accessible :name, :web_address, :notes
belongs_to :location
validates :name, presence: true,
length: { minimum: 5 }
end
然后在视图中:
<%= 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 %>
我从未定义过一个称为update的私有函数,而且我不确定从哪里开始调试它。
对于小于4的Rails版本,应该使用update_attributes。
Persistence#update在Rails4之前是私有的
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句