Wednesday, 11 September 2013

Can my controllers inherit in 4 levels (rails)?

Can my controllers inherit in 4 levels (rails)?

I have 3 levels of my own controllers, because I otherwise would have to
face a lot of duplication. The 1st level then inherits from
InheritedResources::Base from the gem inherited_resources.
3rd level:
#controllers/hosts/feedback_hosts_controller.rb
class Hosts::FeedbackHostsController < HostsController
def scoped_elements
"feedback_hosts"
end
end
2nd level:
#controllers/hosts_controller.rb
class HostsController < ScopedElementsController
end
1st level:
#controllers/scoped_elements_controller.rb
class ScopedElementsController < InheritedResources::Base
def index
@elements = current_user.send(scoped_elements)
end
end
When I visit e.g. /hosts/feedback_hosts I get an error:
NameError - undefined local variable or method `scoped_elements' for
#<Hosts::FeedbackHostsController:0x007fe3f9722290>:
app/controllers/scoped_elements_controller.rb:18:in `index'
Any idea about what I have done wrong?
My routes, btw:
namespace :hosts do
resources :feedback_hosts
resources :social_hosts
end

No comments:

Post a Comment