Product と ProductType の 2 つのモデルがあります。
製品:
class Product < ActiveRecord::Base
default_scope :order => 'name'
has_many :sales
belongs_to :product_type, :class_name => "ProductType", :foreign_key => "type_id"
end
製品タイプ:
class ProductType < ActiveRecord::Base
default_scope :order => 'name'
has_many :products
end
私のroutes.rbには、次のものがあります。
resources :product_types do
resources :products
end
rake routes を実行すると、次の URL が存在することがわかります。
product_type_product GET /product_types/:product_type_id/products/:id(.:format) {:controller=>"products", :action=>"show"}
私が抱えている問題は、http://localhost:3000/postering_locations/48/usersに移動すると、ID 48 のポスタリング場所を持つ単一のユーザーが表示されることです。問題は、それが他のすべてのユーザーも表示されます。48 を有効な別の番号に変更すると、同じことが起こります。テーブルに存在しない番号に交換すると、ルーティングエラーが発生するため、部分的に機能しているように感じます。/postering_locations/48/users を実際に postering_location ID として 48 を持つユーザーを表示する方法について何か考えはありますか?
また、routes.rb で /products/ だけを表示できるようにしたい場合は、routes.rb のどこにリソース :products を追加すればよいですか?