【发布时间】:2011-01-07 12:10:23
【问题描述】:
我想在我的应用程序控制器上定义一个方法,然后我可以从任何继承自它的控制器调用该方法。在此方法中,我需要能够获取与调用该方法的任何控制器关联的模型对象。
class ApplicationController < ActionController::Base
def bar
#Access model name here. So inside FooController, it would have Foo.
end
end
class FooController < ApplicationController
def index
bar #Use the method here
end
end
这可能吗?
【问题讨论】:
标签: model controller ruby-on-rails-3