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

Allow retrieving current route name #381

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

janko
Copy link
Contributor

@janko janko commented Dec 22, 2023

As discussed in #380, this is useful for generating path or URL for current route with different parameters, while still reusing configured route definitions.

# locale switcher with query parameter
rodauth.send(:"#{rodauth.route}_path", request.GET.merge("locale" => "br"))
#=> "/create-account?locale=br"

# locale switcher with path prefix, assuming `prefix { "/#{I18n.locale}/auth" }`
I18n.with_locale("br") { rodauth.send(:"#{rodauth.route}_path", request.GET) }
#=> "/br/auth/create-account"

This is the minimal functionality needed to support this use case. I was considering also adding current_path and current_url methods that would utilize this, but thought that might be an overkill for now.

This is useful for generating path or URL for current route with
different parameters, while still reusing configured route definitions.
@jeremyevans
Copy link
Owner

jeremyevans commented Dec 22, 2023 via email

@jeremyevans jeremyevans merged commit fb0041a into jeremyevans:master Dec 27, 2023
15 checks passed
@jeremyevans
Copy link
Owner

Just FYI, I renamed route to current_route after merging, as I think that is a better name (especially given your spec description).

@janko janko deleted the current-route branch December 27, 2023 19:52
@janko
Copy link
Contributor Author

janko commented Dec 27, 2023

Thanks for merging, I agree with the rename 👍🏻

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.

2 participants