質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 3.1

Ruby on Rails バージョン3.1.0はRuby on Railsの特定のバージョンです。2011年8月30日にリリースされました。

Q&A

1回答

4354閲覧

Routing Error uninitialized constant Adminの対処方法について

Tomoaki_Fukuda

総合スコア75

Ruby on Rails 3.1

Ruby on Rails バージョン3.1.0はRuby on Railsの特定のバージョンです。2011年8月30日にリリースされました。

0グッド

0クリップ

投稿2016/03/12 13:16

###前提・実現したいこと
Ruby on rails にてサービスのログイン機能機能を作成しております。
こちらのサイトに倣って作成しておりましたが、最後の「Articles」に「guest@localhost.localdomain」でログインする際に、下記のエラーメッセージが表示されてしまいます。
この対処方法を教えて頂けないでしょうか?
※その他不足情報ございましたら、ご教示願います。

###エラーメッセージ
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

Rails.application.routes.draw do resources :articles mount RailsAdmin::Engine => '/admin', as: 'rails_admin' devise_for :users root 'admin/base#index' # ログイン画面をルートにする get '/admin' => 'admin/base#index' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" # root 'welcome#index' # Example of regular route: # get 'products/:id' => 'catalog#view' # Example of named route that can be invoked with purchase_url(id: product.id) # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase # Example resource route (maps HTTP verbs to controller actions automatically): # resources :products # Example resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Example resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Example resource route with more complex sub-resources: # resources :products do # resources :comments # resources :sales do # get 'recent', on: :collection # end # end # Example resource route with concerns: # concern :toggleable do # post 'toggle' # end # resources :posts, concerns: :toggleable # resources :photos, concerns: :toggleable # Example resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end end

##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 36 end 37 end 38end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

https://teratail.com/questions/29697
これと同じエラーですね。

投稿2016/03/14 09:35

HiroshiWatanabe

総合スコア2160

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問