Can't find a route with an underscore or doesn't treat it properly

前端 未结 2 1476
时光取名叫无心
时光取名叫无心 2021-01-21 20:36

I have this in routes:

Rails.application.routes.draw do
  namespace :api do
    namespace :v3_4 do
      # .....

And the controller app/c

2条回答
  •  不思量自难忘°
    2021-01-21 21:23

    Rails inflects _ to be a word separator, so it searches for Api::V34 you can change that behavior by editing config/initializers/inflections.rb:

    ActiveSupport::Inflector.inflections(:en) do |inflect|
      inflect.acronym 'V3_4'
    end
    

    Moreover, if you want to change Api namespace to API, since it's an acronym, you can do it there as well:

    ActiveSupport::Inflector.inflections(:en) do |inflect|
      inflect.acronym 'V3_4'
      inflect.acronym 'API'
    end
    

    More info: http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html

提交回复
热议问题