简体   繁体   English

当控制器中包含模块时,导轨发生错误

[英]rails route error when include module in controller

when I include module in controller, the routing is not work, report 404 not found error, below is my code, very sample 当我在控制器中包含模块时,路由不起作用,报告404未找到错误,以下是我的代码,非常示例

ruby: 2.0, rails: 4.2.3 红宝石:2.0,轨道:4.2.3

routes.rb routes.rb

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

common.rb common.rb

module Common
  class A; end
end

test_controller.rb 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

module/class name should start with capital letter Common module/class名应以大写字母开头Common

module Common
  class A; end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM