Skip to content

Resolve "Make the user view selector replace the view in the current url"

Related to #498 (closed)

Solution

Add redirects for /home/ route and then we can simply use request.params.merge instead of institution_homepage_path.

First attempt (final solution doesn't do this):

This should have been as easy as changing

institution_homepage_path(inst_code: user.inst.code, view: 'elementary')

to

request.params.merge(view: 'elementary')

(which would have simply merged the view parameter to the current path).

However, because of how the routes are ordered, this would have sent users to the /home (legacy) path for the homepage instead of the institution_homepage_path, e.g.,

https://www.galileo.usg.edu/ecg1/home/elementary

instead of the desired path:

https://www.galileo.usg.edu/ecg1/elementary

For that reason, I added the current_path_with_view() method to the application_contoller. This checks if we're on the homepage and uses the explicit institution_homepage_path instead of just merging the view parameter with the current path, i.e.,

  # @param [String] view
  # @param [String] inst_code
  # @return [String]
  def current_path_with_view(inst_code, view)
    if current_page?(institution_homepage_path(view: @view))
      institution_homepage_path(inst_code, view: view)
    else
      request.params.merge(view: view)
    end
  end
Edited by Brad Baxter

Merge request reports

Loading