2011-01-07 47 views
0

我想在我的应用程序控制器上定义一个方法,然后我可以从任何继承它的控制器调用它。在这个方法里面,我需要能够将模型对象与任何一个控制器调用方法相关联。ApplicationController方法中的子控制器的模型名称

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 

这可能吗?

回答

1

尝试

self.class.to_s.chomp "Controller" 
相关问题