M
M
Mimuss2018-10-07 21:28:24
Ruby on Rails
Mimuss, 2018-10-07 21:28:24

How to automatically load controller methods in routes?

Let's say I added a method to the controller with any name. How can I make this method appear automatically in the routes? To not have to always write

get 'controller_name/some_method', to: 'controller_name#some_method'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zaporozhchenko Oleg, 2018-10-09
@c3gdlk

Technically
get 'controller_name/:action_name', to: 'controller_name#resolve'
def resolve
public_send(params[:action_name])
end
But, that's not the Rails way, you're doing something wrong. Rail explicitly asks to describe all the routes for a reason. There will hardly be a lot of them, but this gives information about the application and all kinds of helpers and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question