質問するログイン新規登録

質問編集履歴

3

文言を追記しました。

2017/06/21 07:49

投稿

yamady
yamady

スコア176

title CHANGED
File without changes
body CHANGED
@@ -41,7 +41,7 @@
41
41
  subject
42
42
  end
43
43
  ```
44
- このエラー表示のわけはおそらく、ユーザーにadminが付与されていないというものかと思われますが、ログインしているユーザー状態はadminが「true」で付与されているものなんです・・・。
44
+ このエラー表示のわけはおそらく、ユーザーにadminが付与されていないというものかと思われますが、ログインしているユーザー状態はadminが「true」で付与されているものなんです・・・。(/adminにとぶとエラーが表示されてしまいます。)
45
45
  ![イメージ説明](c285dd52028452590ec49f4c7095e5ed.png)
46
46
 
47
47
  ##該当するソースコード

2

cancan追加後のエラーを追記しました

2017/06/21 07:49

投稿

yamady
yamady

スコア176

title CHANGED
@@ -1,1 +1,1 @@
1
- railsadminでなぜかログイン要求されない件について(rails)
1
+ railsadminでログイン要求されない件について(rails)
body CHANGED
@@ -20,4 +20,117 @@
20
20
 
21
21
  [こちら](https://teratail.com/questions/80814)でDeviseで作成したユーザーをパスワードなしで編集できるようにしてしまったのですが、それが原因となっているのでしょうか・・・
22
22
 
23
- すみませんが、お助けくださいませ・・・
23
+ すみませんが、お助けくださいませ・・・
24
+
25
+ ##[追記] gem cancanを追加しました
26
+
27
+ gem cancan 1.6.10
28
+
29
+ ご指摘にあったので、cancanをgemに追加してみました。
30
+ [こちらの記事](http://qiita.com/yukofeb/items/f445846c91e186669c8f#cancan%E8%A8%AD%E5%AE%9A)にあるようにcancan設定を進めていきましたが、下記のようなエラーが生じてしまいました。
31
+
32
+ ```Ruby
33
+ CanCan::AccessDenied in RailsAdmin::MainController#dashboard
34
+
35
+ You are not authorized to access this page.
36
+
37
+ if cannot?(action, subject, *args)
38
+ message ||= unauthorized_message(action, subject)
39
+ raise AccessDenied.new(message, action, subject)
40
+ end
41
+ subject
42
+ end
43
+ ```
44
+ このエラー表示のわけはおそらく、ユーザーにadminが付与されていないというものかと思われますが、ログインしているユーザー状態はadminが「true」で付与されているものなんです・・・。
45
+ ![イメージ説明](c285dd52028452590ec49f4c7095e5ed.png)
46
+
47
+ ##該当するソースコード
48
+ > rails_admin.rb
49
+
50
+ ```ruby
51
+ RailsAdmin.config do |config|
52
+
53
+ ### Popular gems integration
54
+
55
+ ## == Devise ==
56
+ config.authenticate_with do
57
+ warden.authenticate! scope: :user
58
+ end
59
+ config.current_user_method(&:current_user)
60
+
61
+ ## == Cancan ==
62
+ config.authorize_with :cancan
63
+
64
+ ## == Pundit ==
65
+ # config.authorize_with :pundit
66
+
67
+ ## == PaperTrail ==
68
+ # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
69
+
70
+ ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
71
+
72
+ ## == Gravatar integration ==
73
+ ## To disable Gravatar integration in Navigation Bar set to false
74
+ # config.show_gravatar = true
75
+
76
+ config.actions do
77
+ dashboard # mandatory
78
+ index # mandatory
79
+ new
80
+ export
81
+ bulk_delete
82
+ show
83
+ edit
84
+ delete
85
+ show_in_app
86
+
87
+ ## With an audit adapter, you can add:
88
+ # history_index
89
+ # history_show
90
+ end
91
+ end
92
+ ```
93
+ > ability.rb
94
+ ```ruby
95
+ class Ability
96
+ include CanCan::Ability
97
+
98
+ def initialize(user)
99
+ if user && user.admin?
100
+ can :access, :rails_admin # grant access to rails_admin
101
+ can :manage, :all # allow superadmins to do anything
102
+ end
103
+ end
104
+ end
105
+ ```
106
+ > application.rb
107
+
108
+ ```ruby
109
+ class ApplicationController < ActionController::Base
110
+ protect_from_forgery with: :exception
111
+
112
+ include Jpmobile::ViewSelector
113
+ before_action :set_view_path
114
+
115
+ protected
116
+
117
+ def configure_permitted_parameters
118
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
119
+ devise_parameter_sanitizer.permit(:account_update, keys: [:name, :background, :image])
120
+ end
121
+
122
+ class ApplicationController < ActionController::Base
123
+ rescue_from CanCan::AccessDenied do |exception|
124
+ redirect_to root_url, :alert => exception.message
125
+ end
126
+ end
127
+
128
+ private
129
+
130
+ def set_view_path
131
+ path = request.smart_phone? ? 'smartphone' : 'pc'
132
+ prepend_view_path(Rails.root + 'app/views' + path)
133
+ end
134
+ end
135
+
136
+ ```

1

まだ解決できておりません。

2017/06/21 07:47

投稿

yamady
yamady

スコア176

title CHANGED
File without changes
body CHANGED
File without changes