All Projects → substancelab → Route_downcaser

substancelab / Route_downcaser

Licence: mit
Makes routing in Rails case-insensitive

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Route downcaser

Execution time
How fast is your code? See it directly in Rails console.
Stars: ✭ 67 (-11.84%)
Mutual labels:  rails
Sparkler
A Rails webapp that gathers and displays system statistics from Sparkle app updater (macOS/app versions etc.)
Stars: ✭ 71 (-6.58%)
Mutual labels:  rails
Codetriage
Discover the best way to get started contributing to Open Source projects
Stars: ✭ 1,185 (+1459.21%)
Mutual labels:  rails
Elemental components
Simple view components for Rails 5.1+
Stars: ✭ 68 (-10.53%)
Mutual labels:  rails
Trafficlight
🚦 Flexible NodeJS Routing Decorators for API Routing
Stars: ✭ 69 (-9.21%)
Mutual labels:  routing
Activeadmin dynamic fields
ActiveAdmin plugin to add dynamic behaviors to fields
Stars: ✭ 73 (-3.95%)
Mutual labels:  rails
Parcel Rails
Integration of Parcel Javascript module bundler with Rails
Stars: ✭ 67 (-11.84%)
Mutual labels:  rails
Activeadmin quill editor
Quill Rich Text Editor for ActiveAdmin
Stars: ✭ 76 (+0%)
Mutual labels:  rails
Redmine jenkins
A Redmine plugin which makes building your Jenkins projects easy ;)
Stars: ✭ 69 (-9.21%)
Mutual labels:  rails
Active enumerable
ActiveRecord like query methods for Ruby enumerable collections.
Stars: ✭ 73 (-3.95%)
Mutual labels:  rails
Anycable rails demo
AnyCable Rails demo application and its different variations
Stars: ✭ 68 (-10.53%)
Mutual labels:  rails
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (-9.21%)
Mutual labels:  routing
React Easy Params
🔗 Auto synchronize your state with the URL and LocalStorage.
Stars: ✭ 73 (-3.95%)
Mutual labels:  routing
Active attr
What ActiveModel left out
Stars: ✭ 1,155 (+1419.74%)
Mutual labels:  rails
Test Prof
Ruby Tests Profiling Toolbox
Stars: ✭ 1,193 (+1469.74%)
Mutual labels:  rails
Ifme
Free, open source mental health communication web app to share experiences with loved ones
Stars: ✭ 1,147 (+1409.21%)
Mutual labels:  rails
Baremetrics V1
This was the very first version of Baremetrics from 2013. It's published here for posterity.
Stars: ✭ 73 (-3.95%)
Mutual labels:  rails
Acts as hashids
Use Youtube-Like ID in ActiveRecord seamlessly.
Stars: ✭ 76 (+0%)
Mutual labels:  rails
Hotwire Chat
Hotwire Chat is a demo Ruby on Rails web application built with Hotwire.
Stars: ✭ 73 (-3.95%)
Mutual labels:  rails
System tester
A Development Tool for creating and managing system tests for Ruby on Rails >= 5.1 Applications
Stars: ✭ 73 (-3.95%)
Mutual labels:  rails

= RouteDowncaser

{Build Status}[https://travis-ci.org/substancelab/route_downcaser] {}[https://codeclimate.com/github/substancelab/route_downcaser]

Makes routing in Rails case-insensitive (and other Rack-servers like Sinatra)

This gem hooks into the Rack middleware of Rails. This way all paths are downcased before dispatching to Rails' routing mechanism. Querystring parameters and asset paths are not changed in any way.

== Requirements

This gem is tested with 5.2.x, 6.0.x, 6.1.x. It reportedly also works with Sinata, although I do not use Sinatra myself. Sinatra test-cases will be most welcome.

It has previously worked - and I presume still works - in Rails 5.0.x and 5.1.x.

If you want this functionality in a Rails 2.x-3.0 application, please refer to {this blog post}[http://gehling.dk/2010/02/how-to-make-rails-routing-case-insensitive]. If you need it for Rails 3.1.x or 4.x version 1.2.2 should serve you just fine.

Note: from version 1.2.0, route_downcaser depends on ActiveSupport 3.2 or later. This was necessary to enable support for multibyte characters.

== Installing

=== Rails

Just add the gem to your gemfile and run bundle

  gem 'route_downcaser'

Then restart your Rails server. No configuration is needed. The gem simply hooks itself into the Rack middleware call stack.

If you have a controller named app/controllers/foo_controller.rb and the action index, you can now call it with:

  http://localhost:3000/foo
  http://localhost:3000/Foo
  http://localhost:3000/FOO
  http://localhost:3000/foo/index
  http://localhost:3000/Foo/INDEX
  http://localhost:3000/FOO/IndeX

All the above are valid.

=== Sinatra

In your Gemfile you add the gem:

  gem 'route_downcaser'

In your application.rb you add the following (after loading Sinatra)

  require 'route_downcaser'
  use RouteDowncaser::DowncaseRouteMiddleware

Now this statement

  get '/foo' do
    "Hello"
  end

will respond to all these requests:

  http://localhost:4567/foo
  http://localhost:4567/Foo
  http://localhost:4567/FOO

== Configuration Options

Configuration options can be set using an initializer in your application like so:

  # config/initializers/route_downcaser.rb

  RouteDowncaser.configuration do |config|
    config.redirect = true

    config.exclude_patterns = [
      /assets\//i,
      /fonts\//i,
      /some\/important\/path/i
    ]
  end

=== redirect

With this configuration option set to true, the middleware will 301 redirect all routes to their downcased version. Example: http://localhost:3000/Foo will redirect to http://localhost:3000/foo.

=== exclude_patterns

Array of regular expressions. If the requested path matches one of these expressions, RouteDowncaser will not change anything.

== Background information

Sometimes you may wish to market a url which contains a controller name - like www.myshop.com/specialoffer. If this is done on offline media it will cause potential customers trouble, if they don't use the correct casing. If, for some reason, the user types www.myshop.com/Specialoffer (with capital S), your Rails app will return a 404 not found.

The strange thing is, that {the W3C specification}[http://www.w3.org/TR/WD-html40-970708/htmlweb.html] states:

  URLs in general are case-sensitive (with the exception of machine names). There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive.

So www.myshop.com is case-insensitive and can be written as WWW.MYSHOP.COM, but the path (/specialoffer) is not.

It may make perfect sense for the W3C guys, but not for the average user.

When Rails introduced Rack middleware, it suddenly became possible to hook into the call-stack before the URL is used for action dispatching.

At first I just made this code as a snippet and published it {on my blog}[http://gehling.dk/2010/02/how-to-make-rails-routing-case-insensitive]. But since I found out that many people are actually using this, I finally decided to convert it into a gem.

All it really does is to take the path and downcase it before dispatching. Querystring parameters are NOT touched, they keep their casing, since it may have some contextual meaning.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].