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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:15:48+00:00 2026-05-13T09:15:48+00:00

When should I use :conditions or :requirements in rails routing? Here are two examples:

  • 0

When should I use :conditions or :requirements in rails routing?

Here are two examples:

:conditions

map.connect "/foo/:view/:permalink", :controller => "foo",
    :action => "show", :view => /plain|fancy/,
    :permalink => /[-a-z0-9]+/,
    :conditions => { :method => :get }
end

:requirements

 map.connect 'posts/index/:page',
            :controller => 'posts',
            :action => 'index',
            :requirements => {:page => /\d+/ },
            :page => nil
 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-05-13T09:15:49+00:00Added an answer on May 13, 2026 at 9:15 am

    The only option :conditions takes is :method (i.e. :get, :post, etc.), letting you restrict which methods may be used to access the route:

    map.connect 'post/:id', :controller => 'posts', :action => 'show',
                :conditions => { :method => :get }
    

    :requirements, on the other hand, lets you specify a regular expression that the parameter must match, e.g. if the parameter is a postal code you can give it a regular expression that only matches postal codes:

    map.geocode 'geocode/:postalcode', :controller => 'geocode',
                :action => 'show', :requirements => { :postalcode => /\d{5}(-\d{4})?/ }
    

    (You can even drop :requirements and use this shorter form:)

    map.geocode 'geocode/:postalcode', :controller => 'geocode',
                :action => 'show', :postalcode => /\d{5}(-\d{4})?/
    

    Look under “Route conditions” and “Regular Expressions and parameters” in ActionController::Routing, from which I stole the above examples.

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

Sidebar

Related Questions

I read somewhere that one should never use error conditions as normal program flow.
This question is NOT about race-conditions, atomicity, or why you should use locks in
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
I found two collapsing problems : You should use the same language between domain
MSDN says that you should use structs when you need lightweight objects. Are there
What GUI should use to run my JUnit tests, and how exactly do I
What kind of collection I should use to convert NameValue collection to be bindable
I dont know if I should use the httpcontext caching or the Enterprise Library
It is to my understanding that one should use a forward-class declaration in the
i need a report and i should use pivot table for it.Report will be

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.