"/admin" disappearing from URL after loading the view (Rails)

Viewed 112

After navigating to an admin view, /admin disappears out of the URL.

This is occurring for all routes nested inside namespace :admin do.

Example:

  1. Visiting http://localhost:3000/admin/universities loads the view.
  2. But then the URL in that view changes to http://localhost:3000/universities.
  3. Refreshing the page without manually adding back in the /admin, results in "No route matches".

Server Logs:

Started GET "/admin/universities"
Processing by Admin::UniversitiesController#index as HTML
Rendered admin/universities/index.html.haml within layouts/admin
Rendering admin/universities/index.html.haml within layouts/admin

Route:

namespace :admin do
    ...
    get '/universities', to: 'universities#index', as: :university_index
    ...
end

rake routes:

admin_university_index GET   /admin/universities(.:format)    admin/universities#index

Controller:

class Admin::UniversitiesController < Admin::BaseController

  def index
    @universities = University.all
  end
end

I inherited the app and am having trouble figuring out why this is occuring. Has anyone else had experience with this before?

UPDATE

Could this be caused by turbolinks?

UPDATE

Per request, adding admin/base_controller

# /app/controllers/admin/base_controller.rb
class Admin::BaseController < ApplicationController

  before_action :admin_only
  layout "admin"

  private

    def admin_only
      unless current_user && current_user.role == 'admin'
        redirect_to login_url, :notice => "Unauthorized"
      end
    end

end
2 Answers
Related