Rails 3 アプリケーションで次のルート構成を使用します。
# config/routes.rb
MyApp::Application.routes.draw do
resources :products do
get 'statistics', on: :collection, controller: "statistics", action: "index"
end
end
には、次のStatisticController
2 つの簡単な方法があります。
# app/controllers/statistics_controller.rb
class StatisticsController < ApplicationController
def index
@statistics = Statistic.chronologic
render json: @statistics
end
def latest
@statistic = Statistic.latest
render json: @statistic
end
end
/products/statistics
これにより、 によって正常に処理されるURL が生成されますStatisticsController
。
次の URL につながるルートを定義するにはどうすればよい/products/statistics/latest
ですか?
オプション: 作業定義を問題にしようとしましたが、次のエラー メッセージで失敗します。
undefined method 'concern' for #<ActionDispatch::Routing::Mapper ...