- Read Tutorial
- Watch Guide Video
During our review session, remember we found a bug in our admin dashboard? Let's do that again. Click on the "Admin Dashboard" link, and you'll get this error:
I think this is because of the single table inheritance that we implemented in our code, but didn't add it to our dashboard.
The clue to finding the solution is in the message: "undefined method admin_employee_path
." This means, the administrate
gem creates this route somewhere in the application, and is looking for it when we click on "admin dashboard" link.
To fix this, open routes.rb
, and add a route for employees
.
# config/routes.rb namespace :admin do resources :users resources :posts resources :admin_users resources :employees root to: "users#index" end
I think that should do it.
Restart the server and check the browser. The dashboard is working, but if you click on the "Employees" link, it throws another error for us.
I think this error is because we don't have a controller file for our employee model.
Go to controllers/admin
and create a file called employees_controller.rb
. Copy the code from admin_users_controller.rb
and paste it in the new file. Simply change AdminUsersController
to EmployeesController
.
Next, open controllers/dashboards
and create a file for employee called employee_dashboard.rb
. As with the earlier case, copy code from admin_user_dashboard.rb
, and change the class name to EmployeeDashboard
. Everything else should be the same.
Refresh the browser window, and your "Employees" link should work now.
I'm also quickly going to check our phone validation by entering 11 numbers, and that works as well.
Let's run rspec
, and everything is good there too.