Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url_for() produces path with double namespace #29019

Closed
cristian-rivera opened this issue May 9, 2017 · 4 comments
Closed

url_for() produces path with double namespace #29019

cristian-rivera opened this issue May 9, 2017 · 4 comments

Comments

@cristian-rivera
Copy link

I have routes defined like this:

 namespace :dealer, path: '' do
   resources :images, except: :index do
     resources :comments, only: [:create, :destroy] do
       resources :attachments, only: :show
     end
   end
 end

In my view using link_to [@image, @comment] results in a url named:

dealer_image_dealer_comment_path which doesn't exist. It should be dealer_image_comment_path. Any way to avoid the double namespace?

I'm receiving this error:

undefined method `dealer_image_dealer_comment_path' for #<#<Class:0x007fb599499520>:0x007fb5994980d0>
Did you mean?  dealer_image_comments_path
               dealer_image_comment_path

rake routes:

dealer_image_comments POST      /images/:image_id/comments(.:format)                                                                   dealer/comments#create {:subdomain=>"dealer"}
dealer_image_comment DELETE    /images/:image_id/comments/:id(.:format) 

Rails version: 5.0.2

Ruby version: 2.4.0

@alexcameron89
Copy link
Member

Hey @cristian-rivera, can you provide us with a minimal Rails application so we can reproduce the issue you are seeing?

@cristian-rivera
Copy link
Author

Hey @alexcameron89, here is the link to a test repo I setup https://github.com/cristian-rivera/Example just run rails s and navigate to http://lvh.me:3000/dealer/images/1/comments/new!

@pixeltrix
Copy link
Contributor

@cristian-rivera are you using namespaces for your models, e.g. Dealer::Image and Dealer::Comment ? If so this is a limitation of the way polymorphic_url works. It effectively guesses the url helper name based on the model name and namespaces can cause it to go wrong.

@rails-bot
Copy link

rails-bot bot commented Aug 31, 2017

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-1-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot closed this as completed Sep 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants