【问题标题】:Rails catch-all route prevents calls to /rails/info/routesRails 包罗万象的路线可防止调用 /rails/info/routes
【发布时间】:2016-05-24 00:08:11
【问题描述】:

我正在开发一个 Rails 项目,该项目主要使用包罗万象的路线来渲染 Angular 前端页面。因为这个包罗万象的路线在项目中,所以我现在失去了点击的能力/rails/info/routes 这有点方便。

这是我的 routes.rb 的相关部分:

Rails.application.routes.draw do
  match "/delayed_job" => DelayedJobWeb, :anchor => false, via: [:get, :post]

  namespace :api, format: false, defaults: {format: :json} do
    .....
    get '*path' => 'base#not_found'
  end

  namespace :admin, format: false, except: [:show] do
    .....
    root 'home#index'
  end

  devise_for :users

  get 'styleguide' => 'styleguide#index'
  get '*path' => 'bootstrap#index'
  root 'bootstrap#index'

end

【问题讨论】:

  • 您有什么理由不能在终端中使用rake routes 吗?
  • 这一直是我的解决方法,通常我还是会这样做......只是想知道其他人是否有办法解决这个问题。

标签: ruby-on-rails ruby angularjs


【解决方案1】:

想通了 - 对于遇到此问题的任何人,您都可以添加一个约束,其中请求不以 /rails 开头:

  get '*path' => 'bootstrap#index', constraints: -> (req) { !(req.fullpath =~ /^\/rails\/.*/) }

【讨论】:

  • req.fullpath.start_with?('/rails') 将比正则表达式更快(并且可能更具可读性)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-15
  • 2018-09-04
  • 2013-05-19
  • 1970-01-01
相关资源
最近更新 更多