single quotes for controller generated routes

Hello Ruby on Rails: Core Community,

My name is Cristian and this is my first contribution.

What does it do? Currently, when rails generates a controller it adds a route to routes.rb (ex: get “home/index”). All the routes in routes.rb are written with single quotes. Except the controller generated route. It is written with double quotes. This patch attempts to fix that.


rails new test-app
cd test-app
rails g controller home index
cat config/routes.rb | grep home

Before this patch

get “home/index”

After this patch

get ‘home/index’

I ran the generator tests. I would like to hear the community’s opinion. Is there a specific reason why double quotes are used? If not, I will create the pull request.


No reason as far as I am aware of, in general Rails uses single quotes for generated controller views where it doesn’t need double quotes, so I think it’s ok changing the generated controller route too.

Please make sure to review the documentation and guides looking to fix examples too, if you decide to send a pull request.

action@emmag-55474:~$ cat quotes.rb
require 'benchmark'

n = 50_000_000 do |x|"single") { n.times { 'I am a single quote' } }'double') { n.times { "I am a double quote" }}
action@emmag-55474:~$ ruby quotes.rb
       user system total real
single 7.530000 0.010000 7.540000 ( 14.913394)
double 7.150000 0.040000 7.190000 ( 14.202322)

It’d be better if you compare the same strings.

I don’t think this justifies one over the other. First of all, on my machine, the “winning” version flip flops pretty consistently — each one wins about 50% of the time.

Secondly, a half a second of performance difference over 50 million iterations doesn’t quite feel conclusive that one is inherently more “performant”.

I’m +1 on making the styles match between the default example routes and the generated routes.

My point was that I don't think that single vs. double quotes is
different enough to justify changing it on performance grounds, TJ.
We're in agreement.

Francesco, you're right, I should have made them the same length.

I do think that matching styles is a good reason to change one or the
other, though.

Just for the record, this is a pure stylistic preference unrelated to performance (I don’t think is going to make any difference for parsing).

The idea is that single quotes are more specific, they signal right away to the reader the literal is really really simple. The reader does not need to parse the string to infer that.

This is a nuance, I know people who use always double quotes. That’s fine of course.

We have that preference and the patch is welcome.