When I must create a project with an admin panel, I need to do it fast and my choise for this purpose was rails’ scaffold generators. But I must add an
:admin namespace for all of my controllers for the admin panel. Rails’ default scaffold generator has not a feature like that. So I find a solution with rails admin scaffold gem. This gem is simply make a namespace for scaffold controllers and organize urls and paths accordingly.
Add rails-admin-scaffold gem to gemfile of project
After that, we must generate our model and it’s admin namespaced controller separately.
rails g model Comment title:string description:text
rails g admin:scaffold_controller Comment title:string description:text
You can also determine parent controller with
--parent_controller option like that;
rails g admin:scaffold_controller Comment title:string description:text --parent_controller=admin
This command will generate an admin namespaced comment controller that inherit from admin controller.
class Admin::CommentsController < AdminController
This simple gem is a time saver when you want to use rails’ scaffold generator for an admin panel. It has Rails 4 support and haml, jbuilder options. I wish you can save time with this gem in your next project :)