Search code examples
ruby-on-railsrubyruby-on-rails-3routesnested-resources

Rails 3.1 has_one nested resource: routing not generating "all" paths


I have a has_one relation:

# supplier.rb

  has_one :presentation
...

# presentation.rb

  belongs_to :supplier
...

and the folowing nested routes for them:

# routes.rb

resources :suppliers do
  resource :presentation
end

running rake routesgives:

    supplier_presentation POST ... {:action=>"create", :controller=>"presentations"}
 new_supplier_presentation GET ... {:action=>"new", :controller=>"presentations"}
edit_supplier_presentation GET ... {:action=>"edit", :controller=>"presentations"}
                           GET ... {:action=>"show", :controller=>"presentations"}
                           PUT ... {:action=>"update", :controller=>"presentations"}
                        DELETE ... {:action=>"destroy", :controller=>"presentations"}

Why no name_helper for the show action?

I can override the problem doing something like:

resources :suppliers do
  resource :presentation, :except => :show do
    get "" => "presentations#show", as: "presentation"
  end
end

giving the route:

presentation_supplier_presentation GET ... {:controller=>"presentations", :action=>"show"}

but we all now that's not the right way to deal with it..

ANY SUGGESTIONS?

--

(edited)

supplier_presentation_path(@supplier)

does work, but why?... It doesn't appear when rake routes is executed on my shell...


Solution

  • I dont really know why it's not displayed when you do rake routes but did you try in your code to do supplier_presentation_path(@supplier)? It should work based on your routes.