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
这可能吗?
I want to define a method on my application controller which I can then call from any controller which inherits from it. Inside this method, I need to be able to get the model object associated with whichever controller is calling the method.
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
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Try