【问题标题】:rails route error when include module in controller在控制器中包含模块时出现rails路由错误
【发布时间】:2015-08-10 13:40:24
【问题描述】:

当我在控制器中包含模块时,路由不起作用,报告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

【问题讨论】:

    标签: ruby-on-rails routes


    【解决方案1】:

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

    module Common
      class A; end
    end
    

    【讨论】:

    • 感谢您的回答,这是笔误,我已经更正了
    • 如果您觉得答案有用,请接受@Codisan
    猜你喜欢
    • 2013-06-22
    • 1970-01-01
    • 2015-08-04
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 2018-09-15
    相关资源
    最近更新 更多