Jef*_*eff 3 ruby ruby-on-rails
每当我尝试对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
Run Code Online (Sandbox Code Playgroud)
所以,我认为这个问题发生在我的客户模型中,即:
class Customer < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
attr_accessible :name, :web_address, :notes
belongs_to :location
validates :name, presence: true,
length: { minimum: 5 }
end
Run Code Online (Sandbox Code Playgroud)
然后在视图中:
<%= 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 %>
Run Code Online (Sandbox Code Playgroud)
我从来没有定义过一个名为update的私有函数,我不确定从哪里开始调试它.
| 归档时间: |
|
| 查看次数: |
4677 次 |
| 最近记录: |