简体   繁体   中英

Rails: scaffold. Create admin controller for model

I want to create admin interface for existing model User.

What is the simplest way?
I think, it's scaffolding.

Scaffolding in rails is generated by script( rails generate scaffold ), and there is no options to do it dynamically (like in django), correct?

So how can I create scaffolding controller AdminUsers for model User ? Create AdminUsers scaffolding and replace AdminUser model by User ?

What should I do if model will be changed by migrations? Manually update scaffolding controller and views, right? Is there any automation?

You can generate the files dynamically using scaffolding- the scaffold command can take a namespaced argument.

rails generate scaffold Admin::User

You don't need another model though- your Admin::UsersController and views should be working with the User model.

Using standard solutions such as activeadmin or rails_admin is the simpliest way. If you want something custom and still wondering how to scaffold controller AdminUsers for model User , you might want to take a look at rails-admin-scaffold gem which automates this process and an article with more detailed explanation.

在此输入图像描述

ActiveAdmin is a neat user interface for your Rails application. It gives you a fully customizable user interface to your models.

Site: http://activeadmin.info/

Demo: http://demo.activeadmin.info/admin

Railscasts Episode: http://railscasts.com/episodes/284-active-admin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM