Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to resolve 403 Forbidden error when rendering sign-up view for admins?

Alfred Montalvo Jr asked in Rails

Is there a way to resolve 403 Forbidden error when rendering a sign-up view for admins? This issue does not happen to the user sign-up views.

I am using Rails 6.0.3.5, Ruby 2.7.1 and Devise 4.7.3.

I have followed the information in this link to set-up multiple devise models:
https://github.com/heartcombo/devise/wiki/How-to-Setup-Multiple-Devise-User-Models

I've also checked the 'Admin' directory and view file permissions and they match the same permissions that are used for the 'User' folder and view files.

So I don't understand why a '403 Forbidden' error is returned when trying to render the devise views for the Admins.

Any guidance to help resolve this error would be greatly appreciated.

server LOG messages

render user sign-up view

127.0.0.1 - - [16/Mar/2021:13:34:32 UTC] "GET /users/sign_up HTTP/1.1" 200 26684
https://xxxxxxx.vfs.cloud9.us-east-1.amazonaws.com/ -> /users/sign_up

render admin sign-up view

Started GET "/admins/sign_up" for 99.109.2.188 at 2021-03-16 13:45:06 +0000
127.0.0.1 - - [16/Mar/2021:13:45:06 UTC] "GET /admins/sign_up HTTP/1.1" 403 10
https://xxxxxxx.vfs.cloud9.us-east-1.amazonaws.com/users/sign_up -> /admins/sign_up

routes.rb:

#devise_for :admins
devise_for :admins, path: 'admins', controllers: { sessions: "admins/sessions", registrations: 'admins/registrations', passwords: 'admins/passwords', unlocks: 'admins/unlocks', confirmations: 'admins/confirmations'}
authenticated :admin do
root 'pages#index', as: :authenticated_admin_root
get 'adminpages/adminhome'
end

#devise_for :users
devise_for :users, path: 'users', controllers: { sessions: "users/sessions", registrations: 'users/registrations', passwords: 'users/passwords', unlocks: 'users/unlocks', confirmations: 'users/confirmations'}
authenticated :user do
root 'pages#index', as: :authenticated_user_root
get 'userpages/userhome'
end

####################
# Rails routes:
####################
Prefix Verb URI Pattern Controller#Action
cancel_admin_registration GET /admins/cancel(.:format) admins/registrations#cancel
new_admin_registration GET /admins/sign_up(.:format) admins/registrations#new
edit_admin_registration GET /admins/edit(.:format) admins/registrations#edit
admin_registration PATCH /admins(.:format) admins/registrations#update
PUT /admins(.:format) admins/registrations#update
DELETE /admins(.:format) admins/registrations#destroy
POST /admins(.:format) admins/registrations#create

cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
user_registration PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
POST /users(.:format) users/registrations#create

navbar links:

<li class="nav-item"><%= link_to 'User Sign up', new_user_registration_path, :class => "nav-link" %></li>
<li class="nav-item"><%= link_to 'Admin Sign up', new_admin_registration_path, :class => "nav-link" %></li>
Reply

Update ....I was able to resolve the 403 Forbidden error when rendering the admin sign-up view by starting the rails project over again from scratch and installing/updating web-packer after running bundle install for the new rails project. And then afterwards I installed devise and created the devise models, views and controllers for the admins and users.

The lesson learned was to install and update web-packer before installing devise and generating the devise models, views and controllers for the respective user classes.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.