我有一个模块
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
SomeController#some_action # 在功能测试中工作,但不在 Rails 服务器中!
我尝试了各种形式的模块,扩展 ActiveSupport::Concern,添加包含的块并将规范化更改为类方法,但我得到了相同的结果。为什么这会在功能测试中起作用,而不是在它之外呢?
我觉得我只是错过了一些简单的东西。