閲覧いただき、まことにありがとうございます。
開発環境では問題なく、rails adminに入れるのですが
本番環境(Heroku)では入れずに困っています。。
##エラー
2017-07-06T05:28:09.493509+00:00 app[web.1]: I, [2017-07-06T05:28:09.493401 #4] INFO -- : [5adaee92-b977-4527-a07f-5d3530095dd5] Started GET "/admin" for 58.12.53.66 at 2017-07-06 05:28:09 +0000 2017-07-06T05:28:09.495281+00:00 app[web.1]: I, [2017-07-06T05:28:09.495192 #4] INFO -- : [5adaee92-b977-4527-a07f-5d3530095dd5] Processing by RailsAdmin::MainController#dashboard as HTML 2017-07-06T05:28:09.500953+00:00 app[web.1]: D, [2017-07-06T05:28:09.500885 #4] DEBUG -- : [5adaee92-b977-4527-a07f-5d3530095dd5] User Load (4.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]] 2017-07-06T05:28:09.515841+00:00 app[web.1]: I, [2017-07-06T05:28:09.515719 #4] INFO -- : [5adaee92-b977-4527-a07f-5d3530095dd5] Completed 500 Internal Server Error in 20ms (ActiveRecord: 4.1ms) 2017-07-06T05:28:09.516939+00:00 app[web.1]: F, [2017-07-06T05:28:09.516865 #4] FATAL -- : [5adaee92-b977-4527-a07f-5d3530095dd5] 2017-07-06T05:28:09.517411+00:00 app[web.1]: F, [2017-07-06T05:28:09.517339 #4] FATAL -- : [5adaee92-b977-4527-a07f-5d3530095dd5] NoMethodError (undefined method `admin?' for #<User:0x00000006e2b7f0>): 2017-07-06T05:28:09.517480+00:00 app[web.1]: F, [2017-07-06T05:28:09.517417 #4] FATAL -- : [5adaee92-b977-4527-a07f-5d3530095dd5] 2017-07-06T05:28:09.517574+00:00 app[web.1]: F, [2017-07-06T05:28:09.517485 #4] FATAL -- : [5adaee92-b977-4527-a07f-5d3530095dd5] app/models/ability.rb:5:in `initialize'
##試してみたこと
ユーザーにアクセス権限がないのがまず一番の問題だと考え、
$ heroku run rails c $ 001:0> user = User.find(1) $ 002:0> user.update_attribute(:admin, "true")
と入力してみたところ、下記のエラーがかえってきました。
NoMethodError: undefined method `admin='
##該当するソースコード
ability.rb
ruby
1class Ability 2 include CanCan::Ability 3 4 def initialize(user) 5 if user && user.admin? 6 can :access, :rails_admin # grant access to rails_admin 7 can :manage, :all # allow superadmins to do anything 8 end 9 end 10end
user.rb
ruby
1class User < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :trackable, :validatable, 6 :omniauthable 7 has_many :reviews, dependent: :destroy 8 has_many :user_images 9 mount_uploader :image, ThumbnailUploader 10 accepts_nested_attributes_for :user_images 11 12 class << self 13 def find_for_facebook_oauth(auth) 14 where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 15 user.email = auth.info.email 16 user.password = Devise.friendly_token[0,20] 17 user.name = auth.info.name 18 end 19 end 20 21 def create_unique_string 22 SecureRandom.uuid 23 end 24 25 def create_unique_email 26 User.create_unique_string + "@example.com" 27 end 28 end 29 30 private 31 32 def user_params 33 params.require(:user).permit(:name, :email, :image, user_images_attributes: [:cover_image]) 34 end 35end
すみませんが、どうぞよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー