0

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 controllers 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>

betacar
  • 416
  • 2
  • 9
  • 21
  • Please write some example of how you going to call this method in models – bor1s Jun 13 '11 at 13:48
  • I'm not calling it from a model. I'll call it from a view. It will update a common param that all model have (sort of an active or inactive state). – betacar Jun 13 '11 at 18:03
  • Does `resource.class.model_name` help? – d11wtq Jun 13 '11 at 13:48
  • It returns `undefined method 'resource' for #` – betacar Jun 13 '11 at 18:21
  • Well, you'd have to access it as @recurso, since `resource` isn't actually defined as a method on the controller. I have to admit, I'm not entirely clear on what you're trying to achieve. – d11wtq Jun 14 '11 at 01:42

1 Answers1

0

If if rightly understand you, you can try:

resourse.class
makrusak
  • 459
  • 5
  • 21