0

I ran across some routes that followed this format:

resources :foobar, except: "create"

I was just wondering how it worked to have "except:" instead of the symbol ":except" as I see in most documentation.

What is actually happening in this case? Is it calling a method called "except"? What does the colon do?

Hortitude
  • 12,632
  • 16
  • 54
  • 71

1 Answers1

2

Ruby 1.9 supports a JavaScript-ish Hash syntax so this:

resources :foobar, except: 'create'

is the same as this:

resources :foobar, :except => 'create'

The new syntax has limitations though:

  1. The Hash key must be a symbol.
  2. The key can't be something that you'd normally quote so you can't use it for symbols like :'this.that'.
  3. You can't use it with symbols such as :$set (which appear all over the place if you're using MongoDB).

I'm not sure what the exact restrictions are as I don't use it (I do a fair bit of MongoDB work and I have a thing for consistency) but I think the symbols need to match /^[a-z_]\w*/i (or technically, anything that can be used as a label) to be used with the new format.

Community
  • 1
  • 1
mu is too short
  • 396,305
  • 64
  • 779
  • 743