2016-08-04 1 views
0

에 대한 permit_params을 설정하는 방법이 내 모델은 다음과 같습니다다른 모델

Product.rb :

class Product < ApplicationRecord 
    belongs_to :position 
    has_many :products_sizes 
    has_many :sizes, through: :products_sizes 
    has_many :reviews, dependent: :destroy 
    accepts_nested_attributes_for :products_sizes 
end 

Products_size.rb :

class ProductsSize < ApplicationRecord 
    belongs_to :product 
    belongs_to :size 
    has_many :prices 
    accepts_nested_attributes_for :prices 
end 

Size.rb :

class Size < ApplicationRecord 
    has_many :products_sizes 
    has_many :products, through: :products_sizes 
end 

Price.rb :

class Price < ApplicationRecord 
    belongs_to :products_size 
end 
나는 제품을 업데이트 할 때 내가이 제품에 대한 양식을 만들 필요가 ActiveAdmin을에서

, 내가 양식 외모 때문에 일부 가격을 만들 수를 like :

... #here is the begining of the form 
f.inputs 'Sizes' do 
      f.semantic_fields_for ProductsSize.where(product_id: params[:id], size_id: Product.find(params[:id]).products_sizes.size.to_i).first.prices.new do |ps| 
      ps.input :products_size_id, label: 'Size', as: :select, collection: Product.find(params[:id]).sizes.map { |s| ["#{s.title}", s.id] } 
      ps.input :quantity 
      ps.input :amount 
      li do 
       link_to 'Add size', '#' 
      end 
      end 
     end 

제출 버튼을 클릭 할 때를 제외하고는 모두 가격이 생성되지 않습니다. 제 생각에는 price에 대해 permit_params이 지정되어 있지 않기 때문입니다. 어떻게 지정할 수 있습니까? 감사. 여기

답변

0

은 자신의 PARAMS

+0

예,하지만'permit_params'는 내 'Product' 모델이 아니라'belongs_to : products_size' 관계가있는'Price'를 설정해야합니다. 나는 ProductsSize 모델을 통해'Price'에 도달한다. –

+0

컨트롤러에서 매개 변수를 허용 했습니까? –

0
ActiveAdmin.register Post do 
    permit_params :title, 
       comments_attributes: [:name, :hidden] 
end 

포스트가 moodel이며, 다른 인 코멘트를 사용, 이건 그냥 예를 들어 당신이 active admin

ActiveAdmin.register Post do 
permit_params :title, :content, :author 
end 

에 매개 변수를 허용하는 방법이다. 모델 이름이 price_attributes : [... params ...]를 사용할 수있는 경우 comments_attributes와 함께 주석의 매개 변수를 사용할 수 있습니다.