📜 ⬆️ ⬇️

Meet Active Scaffold

Good day to all! I want to tell you about a wonderful gem (plugin) for Ruby and Rails (I almost did not find any mention of it in Habré).

The purpose of this plugin is to provide a convenient, standard interface out of the box. With adding, deleting, editing, searching, sorting and all this with or without ajax.


')
A miracle is made, as shown, in a few simple steps:

1. We throw a line in the Gemfile
gem 'active_scaffold' 

2. Install gems
 bundle install 

3. We connect styles and scripts
 /*  /app/assets/stylesheets/application.css.scss *= require active_scaffold */ 

 //  /app/assets/javascripts/application.js //= require active_scaffold 

4. Register in the target controller
 class StuffsController < AuditorController active_scaffold :stuff end 

Everything! Next Active Scaffold will pick up the corresponding model itself (in the example, Stuff), find out about its columns in the database table and related models, select 15 (by default) first entries according to the default_scope settings in the model (if specified) and present it to you. Also at the same time (except for displaying HTML) will provide you with API in JSON and XML formats.

Active Scaffold determines the generators active_scaffold and active_scaffold_controller, allowing you to create a model + migration + controller + route or only one controller, respectively. Like that:
 rails generate active_scaffold stub name:string value:integer precise:decimal occurs:date 


The result is this:


ActiveScaffold is friendly with I18n, so Russification should not cause difficulties:
 ru: activerecord: models: stub: one: "" few: "" many: "" other: "" attributes: stub: name: "" value: "" precise: "" occurs: "" created_at: "" updated_at: "" 



Very cool, right?

Also Active Scaffold can display error messages if the model validation fails or something irreparable happens to the server.

But this is all base. Most importantly: Active Scaffold keeps track of relationships between models (entities) and can load related records. Like this:


At the same time, the plugin is well configured:
The source code for the project is available on github, ibid, on the wiki, there is excellent documentation (although a bit scattered and outdated in some places). If all the same something is unclear or something does not work - the project has a live Googlegroup , take a look or ask around there, they will help you (but you see, just before that, see the FAQ in the documentation, right?)

Summarizing


The plugin is perfect for prototyping and creating simple interfaces, if there is a lot of data and they are of the same type (for example, many-many digits). It is also good for various admins, etc.

However, if you need something rather complicated - write your own. Active Scaffold is difficult to configure to handle complex forms, complex representations, work with a many-to-many relationship, work with slyly related entities. It is better to write your own.

That's all. Happy to you developing and do not waste your routine for nothing. For her, and created such amazing plugins. And do not forget to return to open source. (Actually, I was doing this small return right now)

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


All Articles