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 7191465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:44:03+00:00 2026-05-28T19:44:03+00:00

there is a situation where a have multiple controllers like a town_center controller, a

  • 0

there is a situation where a have multiple controllers like a town_center controller, a sawmill controller, a quarry controller and so on.

The urls of my application would probably need to be something like /town_center/view or sawmill/view, quarry/view and the likes.

The problem is how to actually write such routes. For instance, for the town_center controller i have something like :

 scope :path => '/town_center', :controller => :town_center do
    get '/view/' => :view, :as => 'town_center'
  end  

While this works fine, there is a problem. When i actually execute the view action in the town_center controller, there is no simple way to get the id of the building, since it’s not present in the url as a params attribute.

One simple idea would be to create a route like :

get '/view/:name' => :view, :as => 'view_building'

But the problem with that approach is that everything gets redirected to a single controller. So, my question is, how can i make it so that there is an identifier on the url and still redirect to particular controllers ?

Or if you think this is not correct as a general idea, is there a better way to doing that ?

  • 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-28T19:44:05+00:00Added an answer on May 28, 2026 at 7:44 pm

    You could use RESTful routing, which has become the norm for Rails applications.

    MyApp::Application.routes.draw do
      resources :town_centers
      resources :sawmills
      resources :quarries
    end
    

    Edit Or for singular routes, as suggested in the comments:

    MyApp::Application.routes.draw do
      resource :town_center
      resource :sawmill
      resource :quarry
    end
    

    This will automatically give you all of the routes needed for Create, Read, Update, and Destroy your various models.

    Running rake routes will show you all of the routes that your application makes available. This will include GET routes of the format GET /town_centers and GET /town_centers/:id, the latter of which will run a show action in your TownCentersController and render your /views/town_centers/show.html.erb view template.

    If you’re new to Rails and have not yet read the Getting Started or Routing guides, they can be found here:

    Getting Started with Rails: http://guides.rubyonrails.org/getting_started.html

    Rails Routing: http://guides.rubyonrails.org/routing.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation: There are a login page with a login form (form
I have the following situation: There is a tool that gets an XSLT from
I have the following situation: There is one custom view inside of the first
Let's say I have a situation in Silverlight where there is a background thread
Situation is like this: There are independent 5 services. Each service consists of a
I have a situation causing me to have a need to support two different
I have a situation with my MVC2 app where I have multiple pages that
I have situation where I have to handle multiple live UDP streams in the
I have the following situation: There is a windows folder that has been mounted
I need to implement an application that is simultaneously communicating with multiple clients using

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.