2

我正在尝试更新其显示视图中的对象。我一直在关注 railscasts 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
4

2 回答 2

1

<%= form_for @account, :url => { :action => "edit"} do |form| %>

改成

<%= form_for(@account) do |form| %>

于 2013-05-19T03:42:10.093 回答
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
于 2013-05-19T13:16:14.097 回答