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

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

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

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

789閲覧

devise、rails_admin、cancancanを使って特定の管理者のみuserを新規登録できるようなアプリにしたい

hossy03

総合スコア4

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/02/06 13:14

編集2020/02/07 13:14

前提・実現したいこと

Ruby on railsで特定のuserのみがログインできるようなアプリを作ろうとしています。
現在、devise,rails_admin,cancancanのgemを導入して、
userテーブルにはadmin_flg :blooeanカラムを作成し、
admin_flgがtrueのユーザーだけが/adminへアクセスできるようにするところまでできました。
しかし、管理画面から新しいuserを登録しようとするとNoMethodErrorになります。

発生している問題・エラーメッセージ

error

1NoMethodError in RailsAdmin::Main#new 2Showing/Users/*****/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/bundler/gems/rails_admin-692ae9910be9/app/views/rails_admin/main/index.html.haml where line #25 raised: 3 4undefined method `properties' for nil:NilClass 5 6undefined method `type_for_attribute' for Store:Class

terminal

1Processing by RailsAdmin::MainController#index as HTML 2 Parameters: {"model_name"=>"user"} 3 User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 4 ↳ config/initializers/rails_admin.rb:7:in `block (2 levels) in <top (required)>' 5 Rendering /Users/********/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/bundler/gems/rails_admin-692ae9910be9/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/application 6 Rendered /Users/********/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/bundler/gems/rails_admin-692ae9910be9/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/application (Duration: 4.5ms | Allocations: 3663) 7Completed 500 Internal Server Error in 10ms (ActiveRecord: 0.4ms | Allocations: 6428) 8 9 10 11ActionView::Template::Error (undefined method `properties' for nil:NilClass): 12 22: - content_for :contextual_tabs do 13 23: - if checkboxes 14 24: = bulk_menu 15 25: - if filterable_fields.present? 16 26: %li.dropdown{style: 'float:right'} 17 27: %a.dropdown-toggle{href: '#', :'data-toggle' => "dropdown"} 18 28: = t('admin.misc.add_filter') 19 20rails_admin (692ae9910be9) lib/rails_admin/config/fields/types/belongs_to_association.rb:19:in `block in <class:BelongsToAssociation>'

該当のソースコード

rails_admin.rb

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 # == CancanCan == 12 config.authorize_with :cancancan 13 14 ## == Pundit == 15 # config.authorize_with :pundit 16 17 ## == PaperTrail == 18 # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0 19 20 ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration 21 22 ## == Gravatar integration == 23 ## To disable Gravatar integration in Navigation Bar set to false 24 # config.show_gravatar = true 25 26 config.actions do 27 dashboard # mandatory 28 index # mandatory 29 new 30 export 31 bulk_delete 32 show 33 edit 34 delete 35 show_in_app 36 37 ## With an audit adapter, you can add: 38 # history_index 39 # history_show 40 end 41end 42

試したこと

https://www.gitmemory.com/issue/sferik/rails_admin/3187/528053850
上記の記事を参考にrails_adminのバージョンが古いのかと考え、bundle update rails_adminをしましたが変化はありませんでした。

補足情報(FW/ツールのバージョンなど)

rails 6.0.2
ruby 2.5.1
rails_admin 2.0.0

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問