前提・実現したいこと
Ruby on rails にてサービスのログイン機能機能を作成しております。
Users/sign_inにアクセスする際に、下記のエラーメッセージが表示されてしまいます。
この対処方法を教えて頂けないでしょうか?
※その他不足情報ございましたら、ご教示願います。
エラーメッセージ
Routing Error
uninitialized constant Admin
Rails.root: /Users/TOMOAKI/chinaEC
Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#Action
Path / Url
articles_path GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article_path GET /articles/new(.:format) articles#new
edit_article_path GET /articles/:id/edit(.:format) articles#edit
article_path GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
rails_admin_path /admin RailsAdmin::Engine
new_user_session_path GET /users/sign_in(.:format) devise/sessions#new
user_session_path POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session_path GET /users/sign_out(.:format) devise/sessions#destroy
user_password_path POST /users/password(.:format) devise/passwords#create
new_user_password_path GET /users/password/new(.:format) devise/passwords#new
edit_user_password_path GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration_path GET /users/cancel(.:format) devise/registrations#cancel
user_registration_path POST /users(.:format) devise/registrations#create
new_user_registration_path GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration_path GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root_path GET / admin/base#index
admin_path GET /admin(.:format) admin/base#index
Routes for RailsAdmin::Engine
dashboard_path GET / rails_admin/main#dashboard
index_path GET|POST /:model_name(.:format) rails_admin/main#index
new_path GET|POST /:model_name/new(.:format) rails_admin/main#new
export_path GET|POST /:model_name/export(.:format) rails_admin/main#export
bulk_delete_path POST|DELETE /:model_name/bulk_delete(.:format) rails_admin/main#bulk_delete
bulk_action_path POST /:model_name/bulk_action(.:format) rails_admin/main#bulk_action
show_path GET /:model_name/:id(.:format) rails_admin/main#show
edit_path GET|PUT /:model_name/:id/edit(.:format) rails_admin/main#edit
delete_path GET|DELETE /:model_name/:id/delete(.:format) rails_admin/main#delete
show_in_app_path GET /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app
Request
Parameters:
None
Toggle session dump
Toggle env dump
Response
Headers:
None
Config>locales>routes.rb
ruby
1Rails.application.routes.draw do 2 resources :articles 3 mount RailsAdmin::Engine => '/admin', as: 'rails_admin' 4 devise_for :users 5 6 root 'admin/base#index' # ログイン画面をルートにする 7 get '/admin' => 'admin/base#index' 8 # The priority is based upon order of creation: first created -> highest priority. 9 # See how all your routes lay out with "rake routes". 10 11 # You can have the root of your site routed with "root" 12 # root 'welcome#index' 13 14 # Example of regular route: 15 # get 'products/:id' => 'catalog#view' 16 17 # Example of named route that can be invoked with purchase_url(id: product.id) 18 # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 19 20 # Example resource route (maps HTTP verbs to controller actions automatically): 21 # resources :products 22 23 # Example resource route with options: 24 # resources :products do 25 # member do 26 # get 'short' 27 # post 'toggle' 28 # end 29 ## Example resource route with sub-resources: 30 # resources :products do 31 # resources :comments, :sales 32 # resource :seller 33 # end 34 35 # Example resource route with more complex sub-resources: 36 # resources :products do 37 # resources :comments 38 # resources :sales do 39 # get 'recent', on: :collection 40 # end 41 # end 42 43 # Example resource route with concerns: 44 # concern :toggleable do 45 # post 'toggle' 46 # end 47 # resources :posts, concerns: :toggleable 48 # resources :photos, concerns: :toggleable 49 50 # Example resource route within a namespace: 51 # namespace :admin do 52 # # Directs /admin/products/* to Admin::ProductsController 53 # # (app/controllers/admin/products_controller.rb) 54 # resources :products 55 # end 56 # end 57 # collection do 58 # get 'sold' 59 # end 60 # end 61
models>concerns>ability.rb
ruby
1class Ability 2 include CanCan::Ability 3 4 def initialize(user) 5 # Define abilities for the passed in user here. For example: 6 # 7 # user ||= User.new # guest user (not logged in) 8 # if user.admin? 9 # can :manage, :all 10 # else 11 # can :read, :all 12 # end 13 # 14 # The first argument to `can` is the action you are giving the user 15 # permission to do. 16 # If you pass :manage it will apply to every action. Other common actions 17 # here are :read, :create, :update and :destroy. 18 # 19 # The second argument is the resource the user can perform the action on. 20 # If you pass :all it will apply to every resource. Otherwise pass a Ruby 21 # class of the resource. 22 # 23 # The third argument is an optional hash of conditions to further filter the 24 # objects. 25 # For example, here the user can only update published articles. 26 # 27 # can :update, Article, :published => true 28 # 29 # See the wiki for details: 30 # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities 31 user ||= User.new # guest user (not logged in) 32 if user.has_role?('admin') 33 can :manage, :all 34 else 35 can :manage, :articles 36end 37 end 38end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。