Tag: 分离关注

如何嵌套收集路线?

我在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 这将生成由StatisticsController成功处理的URL /products/statistics 。 如何定义导致以下URL的路由: /products/statistics/latest ? 可选:我尝试将工作定义置于关注点但它失败并显示错误消息: undefined method ‘concern’ […]