【发布时间】:2012-09-20 04:09:14
【问题描述】:
其实这是我的问题。我有一个带有 MainController、HttpHelper 和 ServiceHelper 的 rails 应用程序。
main_controller.rb
class MainController < ApplicationController
include ServiceHelper
def my_method
Service.make_stuff
end
end
service_helper.rb
module ServiceHelper
class Service
include HttpHelper
def self.make_stuff
http__foo
end
end
end
Service = ServiceHelper::Service
http_helper.rb
module HttpHelper
def http__foo
#stuff
params[:bar].nil?
end
end
如果一切正常,这段代码应该会告诉我:bar 参数是否存在,但我有问题。首先,这段代码不起作用,它告诉我http__foo 没有定义,肯定是因为Service 中的include HttpHelper 不起作用。
我的第二个问题是,如果包含工作,params 变量可能会有问题。如果我在控制器中调用这个方法(http__foo)就可以了,但是我从子类中调用它,那么我不确定它是否可靠。
【问题讨论】:
标签: ruby-on-rails ruby dependency-injection helper