---
title: "Rails 6 raises ArgumentError if param contains colon"
description: "Rails 6 raises ArgumentError if custom param contains a colon"
canonical_url: "https://www.bigbinary.com/blog/rails-6-raises-argumenterror-if-custom-param-contains-a-colon"
markdown_url: "https://www.bigbinary.com/blog/rails-6-raises-argumenterror-if-custom-param-contains-a-colon.md"
---

# Rails 6 raises ArgumentError if param contains colon

Rails 6 raises ArgumentError if custom param contains a colon

- Author: Amit Choudhary
- Published: October 15, 2019
- Categories: Rails 6, Rails

The
[:param](https://guides.rubyonrails.org/routing.html#overriding-named-route-parameters)
option in routes is used to override default resource identifier i.e. :id.

Let's take for an example that we want product :name to be as the default
resource identifier instead of :id while defining routes for `products`. In this
case,
[:param](https://guides.rubyonrails.org/routing.html#overriding-named-route-parameters)
option comes handy. We will see below how we can use this option.

Before Rails 6, if
[resource custom param](https://guides.rubyonrails.org/routing.html#overriding-named-route-parameters)
contains a colon, Rails used to consider that as an extra param which should not
be the case because it sneaks in an extra param.

An [issue](https://github.com/rails/rails/issues/30467) was raised in Aug, 2017
which was later fixed in February this year.

So, now Rails 6 raises `ArgumentError` if a
[resource custom param](https://guides.rubyonrails.org/routing.html#overriding-named-route-parameters)
contains a colon(:).

Let's checkout how it works.

#### Rails 5.2

Let's create routes for `products` with custom param as `name/:pzn`.

```ruby

> > Rails.application.routes.draw do
> > resources :products, param: 'name/:pzn'
> > end
> >
```

```plaintext
\$ rake routes | grep products
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:name/:pzn/edit(.:format) products#edit
product GET /products/:name/:pzn(.:format) products#show
PATCH /products/:name/:pzn(.:format) products#update
PUT /products/:name/:pzn(.:format) products#update
DELETE /products/:name/:pzn(.:format) products#destroy
```

As we can see, Rails also considers `:pzn` as a parameter.

Now let's see how it works in Rails 6.

#### Rails 6.0.0.rc1

```ruby

> > Rails.application.routes.draw do
> > resources :products, param: 'name/:pzn'
> > end
> >
```

```plaintext
\$ rake routes | grep products

rake aborted!
ArgumentError: :param option can't contain colons
/Users/amit/.rvm/gems/ruby-2.6.3/gems/actionpack-6.0.0.rc1/lib/action_dispatch/routing/mapper.rb:1149:in `initialize' /Users/amit/.rvm/gems/ruby-2.6.3/gems/actionpack-6.0.0.rc1/lib/action_dispatch/routing/mapper.rb:1472:in `new'
/Users/amit/.rvm/gems/ruby-2.6.3/gems/actionpack-6.0.0.rc1/lib/action_dispatch/routing/mapper.rb:1472:in `block in resources'
...
...
...
```

Here is the relevant [issue](https://github.com/rails/rails/issues/30467) and
the [pull request](https://github.com/rails/rails/pull/35236).

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-raises-argumenterror-if-custom-param-contains-a-colon)
