Rails路由问题 - 数据路由

时间:2015-07-21 17:02:21

标签: ruby-on-rails ruby-on-rails-4 routes

我想要允许多条路线成为:datable,这意味着它们应该按日期过滤。这是我的路线:

# The datable concern
concern :datable do
  member do
    get 'dated/:start_date/(:end_date)', as: 'dated', constraints: {start_date: /\d{4}-\d{2}-\d{2}/, end_date: /\d{4}-\d{2}-\d{2}/}
  end
end

# The route in which it's added
resources :applications, concerns: :datable

理想情况下,这会产生:

/applications/1/dated/:start_date/(:end_date)

但是,我收到了路由错误:

ArgumentError: Missing :action key on routes definition, please check your routes.

显然我错过了:action密钥,但为什么这对于一个问题是必要的呢?它不应该继承它被称为的路线吗?

1 个答案:

答案 0 :(得分:0)

Matt Brictson提请我注意,关注点不知道要在资源​​中路由到哪个动作。这显然是有道理的,但是,我查看了它。

关注完全没问题。要解决我遇到的问题,我需要使用以下内容替换简单的resources :applications

# Leave out the index resource, which is what I am "concerning"
resources :applications, except: [:index]

# Manually create the index route; adding the concern.
get 'applications', to: 'applications#index', as: 'applications', concerns: :datable

像魅力一样工作。谢谢你的提示,马特。我希望这能为这个问题的其他人提供见解。