Ruby on rails 我如何通过编程确定哪些方法被声明为";“助手”;Rails中的控制器使用的方法?
我正在编写一个插件,向控制器添加一个方法,并将其声明为一个helper方法。如果它是静态完成的(而不是通过插件),它看起来会像这样:Ruby on rails 我如何通过编程确定哪些方法被声明为";“助手”;Rails中的控制器使用的方法?,ruby-on-rails,ruby,actioncontroller,actionviewhelper,Ruby On Rails,Ruby,Actioncontroller,Actionviewhelper,我正在编写一个插件,向控制器添加一个方法,并将其声明为一个helper方法。如果它是静态完成的(而不是通过插件),它看起来会像这样: # in RAILS_ROOT/app/controllers/stuffed_animals_controller.rb class StuffedAnimalsController < ActionController::Base private def bear 'Teddy Bear' end helper_method
# in RAILS_ROOT/app/controllers/stuffed_animals_controller.rb
class StuffedAnimalsController < ActionController::Base
private
def bear
'Teddy Bear'
end
helper_method :bear
end
# in RAILS_ROOT/app/views/stuffed_animals/index.html.erb:
<%= bear -%>
不幸的是,ActionController::Base
没有:helper\u方法
类方法。有人知道我在哪里可以通过:helper\u方法获得类公开的内容列表吗?知道了
def test_declared_bear_as_helper_method
helper = Object.new
helper.extend StuffedAnimalsController.master_helper_module
assert helper.respond_to?(:bear)
end
def test_declared_bear_as_helper_method
helper = Object.new
helper.extend StuffedAnimalsController.master_helper_module
assert helper.respond_to?(:bear)
end