0

レール3.2。ここでは、 (テーブルの列にある)すべてをhttp://domain.dev/toys表示するようにすべてに指示したいと思います。shopsshop_typetoys

# 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

私は何を間違えましたか?ありがとう。

4

2 に答える 2

2

間違った部分:Shop.find(:all)

制約はルートセグメント用です。

(まあ、動詞ですが、:via;またはメソッドで指定されますRequest。)

于 2012-05-08T17:06:10.350 に答える
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
于 2012-05-08T18:26:01.290 に答える