1

I want an url like this, that is, with a query string key without equal sign:

/users/1?welcome

How to obtain this using url_for? I achieved this at the moment:

Rails.application.routes.url_helpers.url_for controller: 'users',
                                             action: 'show',
                                             id: 1,
                                             only_path: true,
                                             welcome: ''

Which produces this:

/users/1?welcome=
mdesantis
  • 8,257
  • 4
  • 31
  • 63

1 Answers1

3

As another StackOverflow answer explains, the W3C specification says that the query string parameters always have a value. It's best practice to follow this.

If you really want to accomplish this, you need to append the query string manually, as Rails won't allow you to do it. This is quite an error-prone solution though, so I would recommend against it:

path = user_path(id: 1) + '?welcome'
fivedigit
  • 18,464
  • 6
  • 54
  • 58