Rails URL helpers
Topics: Ruby on Rails
Rails URL helpers can generate URLs outside views using the application’s current routes.
Using URL helpers outside views
Instead of building the URL yourself, you can rely on the URL helpers which will always be based on your current routes:
class RequestUserCallBackJob < ApplicationJob
include Rails.application.routes.url_helpers
def perform(user)
Net::HTTP.post(
"http://userinfoapi.com/",
body: {callback_to: user_url(user, host: "myapp.com")})
end
end