I using the Rails resource_controller plugin. I have a ReleasesController, which is nested within a UsersController and a ProjectsController.
Resource_controller fails when it attempts to pull the release from User, but succeeds from Project. The problem under User is finding the Release results in an object of type, Enumerable::Enumerator, and not a Release. The same process to find a Release under Project results in identifying the correct Release instance.
Digging through the r_c code, I've figured out the net methods calls, which I've duplicated the problem within script/console:
>> Project.first.releases.find 17
=> #<Release id: 17, project_id: 1, name: "FORTEEN", lock_version: 10, deleted_at: nil, created_at: "2009-06-22 17:56:10", updated_at: "2009-06-22 19:48:47">
>> User.first.releases.find 17
=> #<Enumerable::Enumerator:0x599e29c>
Any Release method used on the Enumerable::Enumerator fails, of course. Here are the definitions of the releases methods:
User:
def projects
# active is a named_scope on Project
employer ? employer.projects.active : Project.active
end
def releases
projects.collect { |p| p.releases }.flatten
end
Project:
has_many :releases, :dependent => :destroy
I use the User.projects method in the ProjectsControler without difficulty. I suspect the issue lies with the definition of the User.releases method, but appreciate suggestions on how to fix.
Here are my route definitions:
map.resources :projects do |project|
project.resources :releases, :member => { :restore => :get }
end
map.resources :releases,
:member => { :restore => :get },
:except => [ :new, :create ]
map.resources :users, :member_path => '/:id', :nested_member_path =>
'/:user_id' do |user|
user.resources :projects
user.resources :releases,
:member => { :restore => :get },
:except => [ :new, :create ]
end
Thanks! dr