0

think of the resource routing of a photo-class for example.

If I this to my routes.rb I will get following routes:

resources :photos

# GET '/photos/', :to => 'photos#index'
# GET '/photos/:photo_id/, :to => 'photos#show'
# and so on and so on

Now what I want is to replace the word /photos in all the routes with a simple /p so that I can get a short URL like /p/1 for the first photo. Is there a way to simply alter the resource-line or do I have to manually add each route?

2 Answers 2

1

This will make all your routes via :photos through p

resources :p, :controller => "photos" 
Sign up to request clarification or add additional context in comments.

Comments

1

To be more concise and avoid the issue with p_id, you could do it like this :

resources :photos, path: 'p'

This way, you benefits from the readibility on your end (it will generate helpers like edit_photo_path, you will access variables as photo_id in case of a nested route and such) and generate the named URLs you do want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.