当控制器中包含模块时,rails路由错误

时间:2015-08-10 13:40:24

标签: ruby-on-rails routes

当我在控制器中包含模块时,路由不起作用,报告404未找到错误,下面是我的代码,非常样本

ruby​​:2.0,rails:4.2.3

的routes.rb

match ':controller(/:action(/:id))', via: :all

common.rb

module Common
  class A; end
end

test_controller.rb

class TestController < ApplicationController
  include Common  # when I delete this line , this route '/test/hello' works as expected,
                  # otherwise rails reports 404 not found

  def hello
    render :json => {msg: 'hello'}
  end
end

1 个答案:

答案 0 :(得分:0)

module/class名称应以大写字母Common

开头
module Common
  class A; end
end