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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:07:17+00:00 2026-05-28T08:07:17+00:00

I am trying to set up some semistatic page in a rails 3 app,

  • 0

I am trying to set up some semistatic page in a rails 3 app,
I have created a Pages controller with some non restful actions

class PagesController < ApplicationController

  def home
  end
  def about
  end
  def contact
  end
  def monday
  end
  def saturday
  end
  def sunday
  end

end

it’s showing the pages well at pages/monday etc… or /monday etc… if i set up the routes as is rails 3 removing controller name form url

But I was just wondering if it is possible to redirect a missing url to /. As per exampel i have /monday set up, but if one plays with the url and input /tuesday it won’t hit a page. can i redirect this kind of actions?

==EDIT==

I’ve change my code to this:

  resources :pages, :path => '/' do
    collection do
      # # match 'tuesday' => redirect('/')
      # # match 'wednesday' => redirect('/')
      # # match 'friday' => redirect('/')
      %w{home monday thursday saturday sunday about contact resources}.each do |url|
        get url
      end
    end
 end
 match 'pages/*page' => :root

the url rewriting works fine looping through the array.
I tried the put the wild cardline at the bottom of my root files and at the bottom of the resources :page block. But I get a “controller action show could not be found” message.

match 'pages/*page' => :root

IS that the correct place to put it to restrain missing url like /tuesday to generate an error page?
is it also possible to limit this redirection only to a few actions and not to all missing pages? ex only to tuesday, wednesday, friday…

  • 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-28T08:07:18+00:00Added an answer on May 28, 2026 at 8:07 am

    You can use wildcard routes to do this. At the end of your routes.rb just add the line:

    match '*page' => :root
    

    and the missing pages will redirect to root with params[:page] set to the url requested.

    If you want to only redirect missing pages in the Pages controller, do this instead

    match 'pages/*page' => :root
    

    You can read more about routing here. Wildcard routes are explained near the end of the article.

    Hope this helped!

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

Sidebar

Related Questions

I'm trying to set up some semistatic page in a rails 3 app I've
In my ruby(1.9.3) on rails (3.1) app I'm trying to set some conditional behavior
I'm trying to set some class variables to store paths in a Rails application
I am trying to set some actions on a custom ListSelectionListener and although everything
I am trying to set some public static constants on a class conditionally by
I'm trying to set some htaccess rules for a specific Kohana controller. Basically its
I have a Perl script that's trying to set some configured DateTime and DateTime::Duration
I have been trying to set up some symbolic links in the Terminal, and
I'm trying to set up some keycodes for an app I'm working on but
I'm trying to set some default values in my class but can't use gettext

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.