我不断收到错误
Couldnt find <object> without an ID
我要做的就是让我的用户更新他们的联系人信息。
目前,我在控制器中对编辑和更新的定义是:
def edit
@contact = current_user.contacts.find(params[:id])
end
def update
@contact = current_user.contacts.find(params[:id])
if @contact.update_attributes(params[:contact])
redirect_to @contact
else
render action: "edit"
end
end
在我看来,有一个表单调用对象@contact
<%= form_for (@contact) do |f| %>
<div class = "name-field">
<%= f.label :name, f.text_field :name %>
</div>
<div class = "company-field">
<%= f.label :company, f.text_field :company %>
</div>
<div class = "email-field">
<%= f.label :email, f.text_field :email %>
</div>
<div class = "phone-field">
<%= f.label :phone, f.text_field :phone %>
</div>
<div class = "mobile-field">
<%= f.label :mobile, f.text_field :mobile %>
</div>
<div class="actions"><%= f.submit "Update" %></div>
<% end %>
获得有关如何解决此错误的任何建议会很棒:)谢谢汤姆