1
내 컨트롤러에서 동작을 만들 때 [대량 할당 할 수 없음] 모델을 만들려고하는데 오류가 발생했습니다. 내 사양에 , 그 질량 - 할당 모델의 나의 테스트는 그 통과!?!ActiveModel :: MassAssignmentSecurity :: CustomersController # 오류 (attr_accessible이 설정 됨)
내 모델 : 너무 컨트롤러
class Customer < ActiveRecord::Base
attr_accessible :doc, :doc_rg, :name, :birthday, :name_sec, :address, :state_id, :city_id, :district_id,
:customer_pj, :is_customer, :segment_id, :activity_id, :person_type, :person_id
belongs_to :person , :polymorphic => true, dependent: :destroy
has_many :histories
has_many :emails
def self.search(search)
if search
conditions = []
conditions << ['name LIKE ?', "%#{search}%"]
find(:all, :conditions => conditions)
else
find(:all)
end
end
end
I`ve 피곤 세트 attr_accessible, 내 무작위 방식이다.
컨트롤러 :
class CustomersController < ApplicationController
include ActiveModel::MassAssignmentSecurity
attr_accessible :doc, :doc_rg, :name, :birthday, :name_sec, :address, :state_id, :city_id, :district_id, :customer_pj, :is_customer
autocomplete :business_segment, :name, :full => true
autocomplete :business_activity, :name, :full => true
[...]
end
테스트, 내 통과 테스트
describe "accessible attributes" do
it "should allow access to basics fields" do
expect do
@customer.save
end.should_not raise_error(ActiveModel::MassAssignmentSecurity::Error)
end
end
오류 :
ActiveModel::MassAssignmentSecurity::Error in CustomersController#create
Can't mass-assign protected attributes: doc, doc_rg, name_sec, address, state_id, city_id, district_id, customer_pj, is_customer
https://github.com/megabga/crm
1.9.2p320
레일 3.2
맥 OS
페이지 나쁜, 내 컨트롤러에 자사의 가장 오래된 클래스를 설정 내
#create 컨트롤러 메소드의 소스 코드를 표시 할 수 있습니까? 또한 컨트롤러에서 attr_accessible이 필요하지 않으므로 제거해야합니다. 당신의 테스트는 save 테스트이지만 컨트롤러에서 update_attributes를 호출한다고 상상해보십시오. 최소한의 실패 사례를 갖는 데 도움이되며 동작을 복제하기위한 테스트를 작성하는 것이 올바른 길입니다. –
오케이! 내 컨트롤러에서 가장 오래된 클래스를 설정하면 나중에 클래스에이 속성이 없습니다. 고마워, 어디서나 도와 줘. –