path resolves

twitter logo github logo ・1 min read

👍 Case: in not Controller

Assume that, you're in app/service.

class SomeService
  # 🦄 include the url_helpers
  include Rails.application.routes.url_helpers

  user_path
end

👍 Case: in Rails console

app.user_path
#=> "/user"

👍 Case: check current path & action name

[1] pry(#<UserController>)> controller_path
=> "user"

[2] pry(#<UserController>)> action_name
=> "index"

👍 Case: Get an absolute path from the current source file

There are two ways.

File.expand_path(relative_path, __FILE__) # from the current source file
File.expand_path(relative_path, __dir__)  # from the current source file

🔗 Parent Note

twitter logo DISCUSS
Classic DEV Post from May 4

The secret that the fonts industry doesn't want you to know

Finally the story of CSS's most unsung hero

n350071 profile image
Ruby Web Developer. Freelancer.