I want to have a button which goes to a random user on my site. I am using the friendly_id gem so the URLs are, for example, /users/dean and I’ve also set it up so its /dean.
I’m guessing I would add something similar to this in my routes.rb file:
match '/users/random' => 'users#index'
And then some extra code in the user controller?
How would I go about doing this?
Many thanks.
I’d do this:
Define a class method
randomon User model (or in a module that’s included into your model if you’d want to reuse it for other models later).Other ways of getting a random record, if performance becomes an issue.
Add a
randomaction in your UsersController like thisAnd finally create a route