Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Nested resource access problem in resource_controller
    primarykey
    data
    text
    <p>I using the Rails resource_controller plugin. I have a ReleasesController, which is nested within a UsersController and a ProjectsController.</p> <p>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.</p> <p>Digging through the r_c code, I've figured out the net methods calls, which I've duplicated the problem within script/console:</p> <pre><code>&gt;&gt; Project.first.releases.find 17 =&gt; #&lt;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"&gt; &gt;&gt; User.first.releases.find 17 =&gt; #&lt;Enumerable::Enumerator:0x599e29c&gt; </code></pre> <p>Any Release method used on the Enumerable::Enumerator fails, of course. Here are the definitions of the releases methods:</p> <pre><code>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 =&gt; :destroy </code></pre> <p>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.</p> <p>Here are my route definitions:</p> <pre><code> map.resources :projects do |project| project.resources :releases, :member =&gt; { :restore =&gt; :get } end map.resources :releases, :member =&gt; { :restore =&gt; :get }, :except =&gt; [ :new, :create ] map.resources :users, :member_path =&gt; '/:id', :nested_member_path =&gt; '/:user_id' do |user| user.resources :projects user.resources :releases, :member =&gt; { :restore =&gt; :get }, :except =&gt; [ :new, :create ] end </code></pre> <p>Thanks! dr</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload