I use polimorphic_path and it some buggy. This method require some route helper that not defined. How can I define (like regular method) own route helper which will be used like "model_name_path, model_name_url etc"?
This solution worked for me.
Add this code to the end of config/routes.rb
file. Make sure to replace MyApp
with your application's name.
MyApp::Application.routes.named_routes.module.module_eval do
def model_name_path(*args)
# Your code here
end
def model_name_url(*args)
# Your code here
end
end
MyApp::Application.routes.named_routes.instance_eval do
@helpers += [:model_name_path, :model_name_url]
end
These custom methods will be available in controllers, views and tests.
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