質問編集履歴

3

文言を追記しました。

2017/06/21 07:49

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -84,7 +84,7 @@
84
84
 
85
85
  ```
86
86
 
87
- このエラー表示のわけはおそらく、ユーザーにadminが付与されていないというものかと思われますが、ログインしているユーザー状態はadminが「true」で付与されているものなんです・・・。
87
+ このエラー表示のわけはおそらく、ユーザーにadminが付与されていないというものかと思われますが、ログインしているユーザー状態はadminが「true」で付与されているものなんです・・・。(/adminにとぶとエラーが表示されてしまいます。)
88
88
 
89
89
  ![イメージ説明](c285dd52028452590ec49f4c7095e5ed.png)
90
90
 

2

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

2017/06/21 07:49

投稿

yamady
yamady

スコア176

test CHANGED
@@ -1 +1 @@
1
- railsadminでなぜかログイン要求されない件について(rails)
1
+ railsadminでログイン要求されない件について(rails)
test CHANGED
@@ -43,3 +43,229 @@
43
43
 
44
44
 
45
45
  すみませんが、お助けくださいませ・・・
46
+
47
+
48
+
49
+ ##[追記] gem cancanを追加しました
50
+
51
+
52
+
53
+ gem cancan 1.6.10
54
+
55
+
56
+
57
+ ご指摘にあったので、cancanをgemに追加してみました。
58
+
59
+ [こちらの記事](http://qiita.com/yukofeb/items/f445846c91e186669c8f#cancan%E8%A8%AD%E5%AE%9A)にあるようにcancan設定を進めていきましたが、下記のようなエラーが生じてしまいました。
60
+
61
+
62
+
63
+ ```Ruby
64
+
65
+ CanCan::AccessDenied in RailsAdmin::MainController#dashboard
66
+
67
+
68
+
69
+ You are not authorized to access this page.
70
+
71
+
72
+
73
+ if cannot?(action, subject, *args)
74
+
75
+ message ||= unauthorized_message(action, subject)
76
+
77
+ raise AccessDenied.new(message, action, subject)
78
+
79
+ end
80
+
81
+ subject
82
+
83
+ end
84
+
85
+ ```
86
+
87
+ このエラー表示のわけはおそらく、ユーザーにadminが付与されていないというものかと思われますが、ログインしているユーザー状態はadminが「true」で付与されているものなんです・・・。
88
+
89
+ ![イメージ説明](c285dd52028452590ec49f4c7095e5ed.png)
90
+
91
+
92
+
93
+ ##該当するソースコード
94
+
95
+ > rails_admin.rb
96
+
97
+
98
+
99
+ ```ruby
100
+
101
+ RailsAdmin.config do |config|
102
+
103
+
104
+
105
+ ### Popular gems integration
106
+
107
+
108
+
109
+ ## == Devise ==
110
+
111
+ config.authenticate_with do
112
+
113
+ warden.authenticate! scope: :user
114
+
115
+ end
116
+
117
+ config.current_user_method(&:current_user)
118
+
119
+
120
+
121
+ ## == Cancan ==
122
+
123
+ config.authorize_with :cancan
124
+
125
+
126
+
127
+ ## == Pundit ==
128
+
129
+ # config.authorize_with :pundit
130
+
131
+
132
+
133
+ ## == PaperTrail ==
134
+
135
+ # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
136
+
137
+
138
+
139
+ ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
140
+
141
+
142
+
143
+ ## == Gravatar integration ==
144
+
145
+ ## To disable Gravatar integration in Navigation Bar set to false
146
+
147
+ # config.show_gravatar = true
148
+
149
+
150
+
151
+ config.actions do
152
+
153
+ dashboard # mandatory
154
+
155
+ index # mandatory
156
+
157
+ new
158
+
159
+ export
160
+
161
+ bulk_delete
162
+
163
+ show
164
+
165
+ edit
166
+
167
+ delete
168
+
169
+ show_in_app
170
+
171
+
172
+
173
+ ## With an audit adapter, you can add:
174
+
175
+ # history_index
176
+
177
+ # history_show
178
+
179
+ end
180
+
181
+ end
182
+
183
+ ```
184
+
185
+ > ability.rb
186
+
187
+ ```ruby
188
+
189
+ class Ability
190
+
191
+ include CanCan::Ability
192
+
193
+
194
+
195
+ def initialize(user)
196
+
197
+ if user && user.admin?
198
+
199
+ can :access, :rails_admin # grant access to rails_admin
200
+
201
+ can :manage, :all # allow superadmins to do anything
202
+
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
209
+ ```
210
+
211
+ > application.rb
212
+
213
+
214
+
215
+ ```ruby
216
+
217
+ class ApplicationController < ActionController::Base
218
+
219
+ protect_from_forgery with: :exception
220
+
221
+
222
+
223
+ include Jpmobile::ViewSelector
224
+
225
+ before_action :set_view_path
226
+
227
+
228
+
229
+ protected
230
+
231
+
232
+
233
+ def configure_permitted_parameters
234
+
235
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
236
+
237
+ devise_parameter_sanitizer.permit(:account_update, keys: [:name, :background, :image])
238
+
239
+ end
240
+
241
+
242
+
243
+ class ApplicationController < ActionController::Base
244
+
245
+ rescue_from CanCan::AccessDenied do |exception|
246
+
247
+ redirect_to root_url, :alert => exception.message
248
+
249
+ end
250
+
251
+ end
252
+
253
+
254
+
255
+ private
256
+
257
+
258
+
259
+ def set_view_path
260
+
261
+ path = request.smart_phone? ? 'smartphone' : 'pc'
262
+
263
+ prepend_view_path(Rails.root + 'app/views' + path)
264
+
265
+ end
266
+
267
+ end
268
+
269
+
270
+
271
+ ```

1

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

2017/06/21 07:47

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
File without changes