How can I get information about controller and action names for any (not only current) url, if there is a route rule for this?
For example:
function_i_need('/pages/5')
returns
{:controller => 'page', :action => 'show', :id => 5}
UPD: Answer found Rails parse url to hash(Routes)
When writing controllers in Ruby on rails, using before_action (used to be called before_filter in earlier versions) is your bread-and-butter for structuring your business logic in a useful way. It's what you want to use to "prepare" the data necessary before the action executes.
Rails before filters are executed before the code in action controller is executed. The before filters are defined at the top of a controller class that calls them. To set it up, you need to call before_filter method.
Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions. Each action's purpose is to collect information to provide it to a view.
you can do this:
Rails.application.routes.recognize_path "/pages/5"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With