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

  • Home
  • SEARCH
  • 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 9129259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:42:18+00:00 2026-06-17T07:42:18+00:00

I am using Rails and have a user entered field that can become a

  • 0

I am using Rails and have a user entered field that can become a param in the URL. I’d like to add a validation that stops the users from entering any fields that will cause routing errors, as currently if the user enters a value like that we get an error “No route matches [GET]…” So far I know periods and slashes are not allowed…

What regex should I use for my validation? Or what regex does Rails use by default for dynamic segments?

  • 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-17T07:42:19+00:00Added an answer on June 17, 2026 at 7:42 am

    Since no one has actually answered the question, just suggested workarounds. (Which are probably better, if you are in the right circumstances to use them.) I experimented to find the characters that caused issues. I tested all punctuation available on a standard US keyboard. I also tested space and (horizontal) tab. I did not test any extended Unicode punctuation, nor control characters.

    The characters I found to cause problems in Rails 3.2.9, using webrick and the composite_primary_keys gem are:

    ,/.%
    

    To validate that a field contains none of these characters:

    validates :field_name, :format => { :with => /\A[^,\/\.%]*\z/, 
      :message => "commas, slashes, periods, and percent signs (,/.%) are not allowed"}
    

    Many of the other characters I tried are not valid directly in URLs, but Rails automatically URL encodes them so they do not cause an issue.

    As mentioned in the comments on the original question, some of these characters can be enabled by configuring Rails other than the defaults, but in doing so you will disable other features of Rails. To enable them you need to add :constraints or :id settings in your route definition.

    I have not completely tested enabling all these characters, but I believe the consequences are:

    Ch  Consequence of enabling use
    --  ---------------------------------------
    ,   Must not use gem composite_primary_keys
    /   Limits ability to route to child items
    .   Disables automatic format handling
    %   Not sure this can be enabled
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class User in Rails using Mongoid and Devise. I can't seem
new on rails and using windows for now,, i have web page that user
Note: Using Rails 3.1 and current delayed_job gem. I have a User model that
I am using Rails 3.2. I have following models: Blog Comment User class Blog
So I am using Devise for user authentication in my rails app. I have
We have a web app running on Rails, using Devise and OmniAuth for user
I have such problem: I'm using rails, devise gem and jQuery validation plugin. I
I have created models in rails using rails g model User uid:integer name:string and
I'm using Rails 3 with Devise for user auth. Let's say I have a
I have been using Rails for over 4 years so obviously I like Rails

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.