0

내가 제품, 공급자, ShoppingLists투자 지표이 상황이와 다 대다 관계.레일 : 3 개 모델

shopping_list 많은 평가 제품, 특정 각 공급 업체 및 가격 이루어져있다.

class Product < ActiveRecord::Base 
    has_many :valuations 
    has_many :shopping_lists, :through => :valuations 
end 

class Supplier < ActiveRecord::Base 
    has_many :valuations 
    has_many :shopping_lists, :through => :valuations 
end 

class ShoppingList < ActiveRecord::Base 
    has_many :valuations 
    has_many :products, :through => :valuations 
    has_many :suppliers, :through => :valuations 
end 

class Valuation < ActiveRecord::Base 
    belongs_to :product 
    belongs_to :supplier 
    belongs_to :shopping_list 
end 

routes.rb은 다음과 같습니다 : 다음과 같이

내 모델

은이 최선의 해결책이 될 수 있다면

map.resources :shopping_lists do |shopping_list| 
    shopping_list.resources :valuations 
    end 

    map.resources :product 

    map.resources :supplier 

가 궁금 어쨌든 내가 원하는 것입니다 사용자는 원하는대로 많은 수의 목록을 만들 수 있으며 각 목록에는 여러 개의 평가가 있습니다.

처음으로 쇼핑 목록이 만들어지면 값이 적어도이됩니다. 그런 다음 사용자는 shopping_list에 /에서 valuations를 추가/제거 할 수 있습니다.

Ajax 콜백없이 간단하고 우아한 해결책을 원합니다.

컨트롤러 /보기/경로 관점에서 가장 좋은 방법은 무엇입니까? 또는 스키마를 변경해야합니까?

감사합니다.

답변