Ruby on rails 如何将模块混入Rails 3控制器

Ruby on rails 如何将模块混入Rails 3控制器,ruby-on-rails,ruby-on-rails-3,activesupport-concern,Ruby On Rails,Ruby On Rails 3,Activesupport Concern,我有一个模块 module Foo def normalize name # modify and return end end 我可以把它混合到一个模型中很好 class Something include Foo end Something.new.normalize "a string" # works 并尝试混入控制器 class SomeController < ApplicationController include Foo def som

我有一个模块

module Foo
  def normalize name
    # modify and return
  end
end
我可以把它混合到一个模型中很好

class Something
  include Foo
end

Something.new.normalize "a string" # works
并尝试混入控制器

class SomeController < ApplicationController
  include Foo

  def some_action
    normalize "a string"
  end
end
class SomeController
SomeController#someu action#可以在功能测试中工作,但不能在rails服务器中工作

我尝试了各种形式的模块,扩展了ActiveSupport::Concern,添加了一个包含的块,并将normalize更改为一个类方法,但得到了相同的结果。为什么这在功能测试中有效,而不是在功能测试之外

我觉得我错过了一些简单的东西。

它在测试中“起作用”的原因是测试还包括了模块并调用了normalize方法:

class SomeControllerTest < ActionController::TestCase
  include Foo


您重新启动了服务器吗?是的,我重新启动了服务器:)
normalize "a string"
self.normalize "a string"