我在 Rails 3 应用程序中使用以下路由配置。
# config/routes.rb
MyApp::Application.routes.draw do
resources :products do
get 'statistics', on: :collection, controller: "statistics", action: "index"
end
end
StatisticController
有两个简单的方法:
# 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
由StatisticsController
.
如何定义通向以下 URL 的路由:/products/statistics/latest
?
可选:我尝试将工作定义置于关注点,但失败并显示错误消息:
undefined method 'concern' for #<ActionDispatch::Routing::Mapper ...