Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access route path from a Class method in a controller? (Rails)

I have a class method in application_controller.rb:

def self.method1
  path = some_path
end

Now it seems I can't access some_path since usually I'll need to use route in a controller (instance method).

What is the best way to access routes here?

Thanks

like image 582
Eki Eqbal Avatar asked Jan 09 '23 16:01

Eki Eqbal


1 Answers

This should work from anywhere in your application

path = Rails.application.routes.url_helpers.some_path
like image 185
JTG Avatar answered Jan 21 '23 09:01

JTG