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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:52:21+00:00 2026-06-06T16:52:21+00:00

I am working on a Rails app, and I am looking for a way

  • 0

I am working on a Rails app, and I am looking for a way to route to different actions in the controller based on the existence of parameters in the url.

For example I want website.com/model to route to model#index, however I want website.com/model?opt=dev to route to model#show. Is there some way this can be done?

  • 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-06-06T16:52:22+00:00Added an answer on June 6, 2026 at 4:52 pm

    Use route constraints to look at the request object and see if it has URL parameters. If you’re using restful routes, you want to put this “one-off” before the restful route. Something like this:

    get 'users' => 'users#show', constraints: { query_string: /.+/ }
    resources :users
    

    So what this is saying is that if you request “/users?opt=dev” then it will match your special case. Otherwise, it falls through to your normal restful route to the index action. Your model#show action will then have to know to pick up the param[:opt] and do whatever with it.

    Also, note that the regex is very loose and it’s simply checking for ANY param…you’ll want to tighten that up to fit whatever you’re trying to do.

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

Sidebar

Related Questions

I'm looking for a very very simple example where a Rails App does the
I'm looking to use the latest Twitter gem for a Rails app I'm working
I'm working on a Rails app and am looking to include some functionality from
I'm working on a Rails app that sends data through a form. I want
I'm working on my first Rails(3) App, and looking to seed a bunch of
I did heroku create and pushed a working rails app to the server. Everything
I'm working on a Rails app that implements some social network features as relationships,
I am working on rails 3 app and using the koala gem to get
I'm working on a Rails app that existing users can invite additional members to
I am working on a Rails app that allows you to create a configuration

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.