jeremyevans / rodauth

Ruby's Most Advanced Authentication Framework
http://rodauth.jeremyevans.net
MIT License
1.65k stars 95 forks source link

Allow retrieving current route name #381

Closed janko closed 6 months ago

janko commented 6 months ago

As discussed in https://github.com/jeremyevans/rodauth/discussions/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.

jeremyevans commented 6 months ago

Thanks for the patch. I'll probably have time to review on December 27.

jeremyevans commented 6 months ago

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

janko commented 6 months ago

Thanks for merging, I agree with the rename 👍🏻