Rails - uninitialized Admin constant

I am working on creating an admin console for my application.

I added admin_controller.rb ... class AdminController < ApplicationController

Then I added resources :admin to my routes.

Then I added a model that is empty, since there is no DB table for admin views, it just reports other tables:

 class Admin < ActiveRecord::Base end 

In the admin console there will be no model in db.

When I try to access the / admin view, I get an error:

 Access denied on index Admin(Table doesn't exist) 
+4
source share
1 answer

If you inherit from ActiveRecord::Base , you will need a database table. If you do not need a database table, then do not inherit from ActiveRecord::Base .

If you want to use some functions from the active record, such as checks or callbacks, you can enable the modules you need. Here is a good entry that will explain everything:

http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/

+5
source

Source: https://habr.com/ru/post/1342331/


All Articles