2013-05-19 1 views
2

보기 뷰에서 오브젝트를 업데이트하려고합니다. 나는 railscasts을 따라 갔다 HABTM checkboxes.레일 쇼보기에서 편집 작업 사용

다음과 같은 오류 방법 :

<%= 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 

/응용 프로그램/모델/계정 : 여기

No route matches [PUT] "/accounts/4/edit"

나의 형태이다. 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 

답변

1

제가

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

변화

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

변경하고 난 checklist_ids 작성일했다 essible 이후 질량을 할당 할 수 없음 checklist_ids

class Account < ActiveRecord::Base 
    attr_accessible :checklist_ids 
end 
1

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

변화

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