Standard way in ROR to redirect the user is to do:
redirect_to controller: '/some/controller', action: 'some_action', param1: value1, param2: value2, status: :see_other
However in my use case, I want to generate the corresponding URL and render it to the user, which they can click later if they want. Internally,
redirect_to uses a method called
_compute_redirect_to_location to generate the exact URL string, but as per the naming convention, this does not look like a method that was intended to be used directly by an external code.
Is there a proper way to generate this URL and not have to figure out the route then parse and join the params manually? If not, is it safe to use that method outside of gem?
It seems like you are looking for
url_for(controller: '/some/controller', action: 'some_action', param1: value1, param2: value2) #=> "/some/controller/some_action?params1=value1¶ms2=value2"
url_for also accepts parameters like
Or you can use Rails` routes helper, if you set them up correctly (see: RailsGuides - Rails Routing from the Outside In).