Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of using url_helpers in resolvers #4009

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Mar 29, 2022

A problem I’ve been struggling with is generating URLs within the resolvers using the current host and port. A common solution is to set Rails.application.routes.default_url_options, but this is static and with my current setup I need to be able to return the host actually used within the request (My development environment runs over both http and https, so I can’t just hardcode localhost:3000).

A solution I’ve found is to pass the controller’s request into the context, and use the ActionController::UrlFor concern.
And likewise for Active Storage, ActiveStorage::SetCurrent works similarly.

I thought it might be useful to share this with anyone else running into this use case.

A problem I’ve been struggling with is generating URLs within the resolvers using the current host and port. A common solution is to set `Rails.application.routes.default_url_options`, but this is static and with my current setup I need to be able to return the host actually used within the request (My development environment runs over both http and https, so I can’t just hardcode localhost:3000).

A solution I’ve found is to pass the controller’s request into the context, and use the `ActionController::UrlFor` concern.
And likewise for Active Storage, `ActiveStorage::SetCurrent` works similarly.

I thought it might be useful to share this with anyone else running into this use case.
@rmosolgo
Copy link
Owner

Thanks for sharing what you found 👍

@rmosolgo rmosolgo merged commit 170b402 into rmosolgo:master Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants