rails_adminで管理者画面を作りました。最初は上手く行ったのですが5回目くらいのときに以下のエラーが出て困っています。原因・解決方法がわかる方は教えていただけると幸いです。https://qiita.com/mailok1212/items/8e36a5a10f19023bb0c4←参考にしたサイト
error
1Started GET "/admin" for ::1 at 2019-11-27 17:23:30 +0900 2 (19.4ms) SELECT sqlite_version(*) 3 (2.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC 4Processing by RailsAdmin::MainController#dashboard as HTML 5 User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 63], ["LIMIT", 1]] 7 ↳ config/initializers/rails_admin.rb:7:in `block (2 levels) in <top (required)>' 8Completed 500 Internal Server Error in 93ms (ActiveRecord: 7.7ms | Allocations: 9176) 9 10 11NoMethodError (undefined method `new' for nil:NilClass):
gem
1(今回使用したもの) 2gem 'devise' 3gem 'rails_admin' 4gem 'rails-i18n' 5gem 'cancancan'
railsadminrb
1RailsAdmin.config do |config| 2 3 ### Popular gems integration 4 5 ## == Devise == 6 config.authenticate_with do 7 warden.authenticate! scope: :user 8 end 9 config.current_user_method(&:current_user) 10 11 ## == Cancan == 12 config.authorize_with :cancan 13 14 ## == Pundit == 15 # config.authorize_with :pundit 16 end
Ability
1# frozen_string_literal: true 2 3class Ability 4 include CanCan::Ability 5 6 def initialize(user) 7 if user.try(:admin?) 8 can :access, :rails_admin 9 can :manage, :all 10 # Define abilities for the passed in user here. For example: 11 # 12 # user ||= User.new # guest user (not logged in) 13 # if user.admin? 14 # can :manage, :all 15 # else 16 # can :read, :all 17 # end 18 # 19 # The first argument to `can` is the action you are giving the user 20 # permission to do. 21 # If you pass :manage it will apply to every action. Other common actions 22 # here are :read, :create, :update and :destroy. 23 # 24 # The second argument is the resource the user can perform the action on. 25 # If you pass :all it will apply to every resource. Otherwise pass a Ruby 26 # class of the resource. 27 # 28 # The third argument is an optional hash of conditions to further filter the 29 # objects. 30 # For example, here the user can only update published articles. 31 # 32 # can :update, Article, :published => true 33 # 34 # See the wiki for details: 35 # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities 36 end 37 end 38end
https://qiita.com/Masahiro_T/items/130d7cda3ea5de08985eこのサイトの方法を試しましたが、you are not authorized to access this page. といわれてしまいます。
>you are not authorized to access this page. といわれてしまいます。 cancancanって確か権限周りのgemだったと記憶していますが、開こうとした画面に対してログインしたユーザーの権限が無いのでは? 冒頭のエラーは既に直っていて、別の現象が発生しているように見えますがいかがでしょう?
回答1件
あなたの回答
tips
プレビュー