开发者

Rails: access resource model from ApplicationController

开发者 https://www.devze.com 2023-03-12 07:01 出处:网络
So, I\'ve the following method in the ApplicationController, which is need to be accessed by all controllers:

So, I've the following method in the ApplicationController, which is need to be accessed by all controllers:

  def alter_some_attribute
    @recurso = resource.find(params[:id])

    ...
  end

This method only alters a common attribute that all models have. I've tested and the contro开发者_StackOverflow社区llers access pretty good to the method. The question is how do I get the models name of the resource who access the method?

I've tried resource, resource_model, resource[:model] and all of them return the error: undefined method 'resource' for #<SomeController:0xb64a1418>


If if rightly understand you, you can try:

resourse.class
0

精彩评论

暂无评论...
验证码 换一张
取 消