How to access the _ _path and * _url helpers in Rails 4

I read Rails: I checked the output of the path helper from the console , and none of the solutions worked for me, apparently because they are all for Rails 2/3.

In Rails 4/5, how can I access the * _path and * _url helpers from the rails console?

+5
source share
2 answers

Running Rails 4, I get with them:

app.root_path => "/" app.users_url => "http://www.example.com/users" 
+15
source

You can use Rails.application.routes.url_helpers

  Rails.application.routes.url_helpers.users_path 

For * _url versions you will need to inform the host about this or set it as default

specify host:

  Rails.application.routes.url_helpers.users_url(:host => 'http://example.com') 

set default value:

 Example::Application.configure do routes.default_url_options = {:host => 'http://example.com'} end 
+9
source

Source: https://habr.com/ru/post/1244770/


All Articles