我正在尝试更新其显示视图中的对象。我一直在关注railscast HABTM checkboxes。
收到以下错误:
没有路线匹配[PUT]“/ accounts / 4 / edit”
这是我的表格:
<%= form_for @account, :url => { :action => "edit"} do |form| %>
<%= hidden_field_tag "account[checklist_ids][]", nil%>
<% Checklist.all.each do |checklist| %>
<%= check_box_tag "account[checklist_ids][]", checklist.id, @account.checklist_ids.include?(checklist.id) %>
<%= checklist.task %><br/>
<% end %><br/>
<%= form.submit "Update Checklist", class: 'btn' %>
<% end %>
/app/controllers/accounts_controller.rb
class AccountsController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :json
def show
@account = Account.find(params[:id])
@notes = @account.notes.all
@contacts = @account.contacts.all
end
def edit
@account = Account.find(params[:id])
end
def update
@account = Account.find(params[:id])
@account.update_attributes(params[:account])
respond_with @account
end
end
/app/models/account.rb
class Account < ActiveRecord::Base
attr_accessible :address, :city, :name, :phone, :state, :website, :zip, :contactname
attr_accessible :conferences_attributes, :checklists_attributes
has_many :notes, :dependent => :destroy
has_many :accountchecklists
has_many :checklists, :through => :accountchecklists, :dependent => :destroy
has_many :contacts, :dependent => :destroy
has_and_belongs_to_many :conferences
accepts_nested_attributes_for :conferences
accepts_nested_attributes_for :checklists
end
答案 0 :(得分:1)
<%= form_for @account, :url => { :action => "edit"} do |form| %>
更改为
<%= form_for(@account) do |form| %>
答案 1 :(得分:1)
我改变了
<%= form_for @account, :url => { :action => "edit"} do |form| %>
更改为
<%= form_for @account, :url => { :action => "update"} do |form| %>
然后我让checklist_ids可以访问,因为我得到了一个无法批量分配checklist_ids
class Account < ActiveRecord::Base
attr_accessible :checklist_ids
end