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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:39:09+00:00 2026-06-13T18:39:09+00:00

According to the Rails Routing Redirection guide , there doesn’t seem to be an

  • 0

According to the Rails Routing Redirection guide, there doesn’t seem to be an easy way to redirect a matched URL to another named URL within the routes file.

I wish I could redirect like this, or something similar, in my routes.rb without having specify the full url path ("/articles/%{id}") in the redirect function.

match "articles/:id" => "articles#show", :as=>'article'
match "articles/view/:id", :to => redirect(article_path) 

Is there a plugin or gem that might provide this functionality?


My final solution included adding a function like the following based on the accepted answer.

# handles redirecting a matched URL to a named URL
# source_match = string to match against
# dest_name = symbol of the named URL 
def redirect_to_url(source_match,dest_name)
    param_symbols = source_match.scan(/:([a-z\-\_]+)/i).flatten.map{|i| i.to_sym}
    match source_match, :to=>redirect{|params,request| 
        Rails.application.routes.url_helpers.send("#{dest_name}_path", params.slice(*param_symbols))
    }
end
  • 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-13T18:39:10+00:00Added an answer on June 13, 2026 at 6:39 pm

    This is achievable, you just have to refer straight to Rails URL helpers module through the lambda version of the redirect since you need this to be lazily resolved:

    match "articles/view/:id", redirect {Rails.application.routes.url_helpers.article_path}
    

    Note that this might not work since article_path requires an id to be passed to in order to operate.
    If this is the case you can use params which are passed to the lambda version of the redirect directive:

    match "articles/view/:id", redirect {|params, request| Rails.application.routes.url_helpers.article_path(params[:id]) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if there's any way for a Rails asset to vary according to
According to this Rails guide , if you create a fixture, it becomes available
According to the Rails API (snippet below), the optimal way to receive mail is
Rails 3.0.9 I configured routes according to http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-url-params But seems that info there is
according to this (older) post these Rails 3 finders have race conditions. Something like
I have Rails polymorphic model and I want to apply different validations according to
According to the Ruby on Rails 2.3 Release Notes... if your plugin has an
According to the present Rails documentation, regarding the << operator on a has_many relationship
I am relatively new to ruby on rails, so this question might be easy.
I understand that according to Rails philosophy, data integrity checks should be done at

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.