Ken W
Ken W

Reputation: 962

Rails: restful resource routing with action_controller_path

I am putting a randomize def in my controller and would like to access it with a restful route. The route should be accessed with the following:

<%= link_to "Randomize", random_reader_path %>

But I cannot figure out how to get this route to appear in rake routes or configure it correctly in my routes.rb file.

The random method will do the same thing as index only provide a random page content @variable

Currently I have my reader Controller as

resources :reader

in my routes.rb

Upvotes: 0

Views: 273

Answers (1)

Buck Doyle
Buck Doyle

Reputation: 6397

Add more RESTful actions!

resources :reader do
  get 'random', on: :collection
end

The route will be random_readers_path, though.

Upvotes: 2

Related Questions