Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7037419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:32:34+00:00 2026-05-28T01:32:34+00:00

My project has files and folders, represented by File and Folder models. The project

  • 0

My project has files and folders, represented by File and Folder models. The project is functionally complete, and now I’m looking to cleanup the URI scheme while keeping my named routes.

My route contains a simple nested resource:

resources :folders do
  resources :files
end

Currently, folder_file_path(@folder, @file) outputs:

/folders/12/files/3

I’ve overridden to_param to output a human-readable slug, yielding

/folders/my-folder/files/my-file

I’d like to go a step further and remove the redundant folders and files segments from the URI. How can I modify my nested resources so that folder_file_path will output the following?

/my-folder/my-file

I’d like to keep my routes simple, using nested resources instead of moving to a longer mess of custom named routes, which is how I’ve currently achieved this:

get ':folder_slug' => 'folders#show', :as => 'folder'
get ':folder_slug/edit => 'folders#edit', :as => 'edit_folder'
# ...
delete ':folder_slug' => 'folders#destroy', : as => 'folder'

get ':folder_slug/:file_slug' => 'files#show', :as => 'folder_file'
get ':folder_slug/:file_slug/edit' => 'files#edit', :as => 'edit_folder_file'
# ...
delete ':folder_slug/:file_slug' => 'files#delete', :as => 'folder_file'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:32:34+00:00Added an answer on May 28, 2026 at 1:32 am

    Something like this

    resources :folders, path: ''
    resources :folders, path: '', only: [] do
      resources :files, path: ''    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

master branch has these files and folders (simplified): C:\Local\TickZoom\Project>ls file.txt name.txt public public branch
I've a Java project which has some resources located in a folder named files
I have the following situation. My project has a main.scala.html file and a folder
In my C++ project, one of the .cpp files has a class declared. Now
I'm working on a project where someone has checked in some folders and files
My Project has 2 java files (A.java and B.java in same package). A.java uses
I'm working on a very large project that has associated class files in multiple
My project (an interpreted language) has a standard library composed by multiple files, each
I have a web site project with a lot of files, it has become
My project has a file foo that I've been using and checking in with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.