-1

I am working on a website and I am trying to change how the URL looks for the users. As I have all my resources nested, I struggle a lot to do what I want.

At the moment, here are my routes

 resources :folders do
   resources :portfolio_photos
 end

I've changed it to this, which works for the folders index.

 resources :folders, except: [:index] do
   resources :portfolio_photos
 end
 get '/photos', to: 'folders#index'

The only problem is that I also want the "portfolio_photos" url to look like this

  /photos/:id/portfolio_photos 

(and I don't want to change the name of my model).

I've tried that:

get '/photos/:id/portfolio_photos', to: 'portfolio_photos#index' 

but it is not working.

Even better would be to get a completely custom URL looking like that on the surface : www.xxxx.com/portfolio_photos even if everything is nested in the backend. Is there a way to change how the url looks without touching the whole backend?

Thanks a lot for your help!

Jessicascn
  • 151
  • 1
  • 13

1 Answers1

1

After 2 hours of researches, I've found this:

resources :folders, :path => 'photos' do
   resources :portfolio_photos
end

Works perfectly and I just had to change the routes file!

Posting it as it will maybe help someone :)

Thanks everyone

Jessicascn
  • 151
  • 1
  • 13
  • Well, this will **not generate** `/photos/:id/portfolio_photos`which you wanted. It will generate this `/photos/:folder_id/portfolio_photos` instead – Pavan Sep 19 '18 at 12:47
  • Yes, that's what I wanted, I thought :id and :folder_id here was the same thing as in this case photos is still a "nickname" for my folder. Sorry my question was not clear, I am probably more confused with routes than I thought! – Jessicascn Sep 19 '18 at 12:51