Rails 3.2。在这里,我想指示所有http://domain.dev/toys
仅显示shops
shop_type
(在我的表格列中)为toys
的所有# routes.rb
resources :shops
match 'toys' => 'shops#index', :as => :toys, :via => :get, :constraints => {:shop_type => 'toys'}
# shops_controller.rb
def index
@shops = Shop.find(:all)
end
。
{{1}}
我做错了什么?感谢。
答案 0 :(得分:2)
答案 1 :(得分:0)
在routes.rb
:
match 'shops(/:shop_type)' => 'shops#index', :via => :get, :as => :shops_path
在shops_controller.rb
:
SHOP_TYPES = [:toys, :clothing, :accessories]
def index
@shops = []
if SHOP_TYPES.include? params[:shop_type].to_sym
@shops = Shop.find_all_by_shop_type(params[:shop_type])
else
@shops = Shop.find(:all)
end
end