stores
에 대해 중첩 된 양식 categories
을 가지고 있으며 저장소 모델에 attr_accessible로 나열되어 있습니다. 하지만 여전히 다음과 같은 오류가 점점 계속 :레일 3.1 - 보호 속성을 지정할 수 없습니다 (attr_accessible에 추가 되었음에도 불구하고)
WARNING: Can't mass-assign protected attributes: category_ids
내가 가게 모델에서 attr_accessible의 모든 변화를 시도했다 : 그들 중
attr_accessible :categories
attr_accessible :category
attr_accessible :category_id
attr_accessible :category_ids
를 수행해도 문제가 해결되지 않는! 이 두 모델은 모두 has_and_belongs_to_many (및 categories_stores라는 조인 테이블이 있음)입니다.
조언을 주시면 감사하겠습니다 (이 기간 동안 이틀 동안 벽에 머리를 두드 리고 있습니다). 나는 (꽤 중복 난간 바로 위의 문제에 부착 된 경우에는 필요하지 않음) 임시 수정을 구현했습니다
UPDATE. 나는 ActiveAdmin을위한 create
방법을 덮어 쓰기 및 연관 데이터를 삽입 반복하여 고정 : 당신이 가입 테이블이라고 categories_stores이있는 경우
controller do
def update
@store = store.find(params[:id])
if @store.update_attributes(params[:store])
@store.categories.delete_all
params[:store][:category_ids].each do |category_id|
@store.categories << Category.find(category_id) unless category_id.blank?
end
redirect_to :action => :index
else
redirect_to :action => :edit, :notice => "Something f'ed up"
end
end
end
심지어 모델과 여전히 이동 모두 attr_accessible을 제거하려고했습니다! – Hopstream