SmartManaging
SmartManaging is a tool which allow create easily a beautiful management interface while keeping the agility and the power of Rails.
Demo
You can find a demo application here and the source of the demo here.
Install in an existing project
SmartManging uses SmartListing, SimpleForm and Twitter-Bootsrap. You must to install it before to install SmartManaging.
To install SmartManaging you have to add this in your Gemfile :
gem 'smart_listing', github: 'GCorbel/smart_listing'
gem 'smart_managing'Bundle it by using the command bundle install.
Finally, you must to add this line in you controller :
include SmartManaging::ControllerHelpersStart from scratch
Here is an example of managing interface in less than 30 seconds
Create the application :
rails new UserManagement --skip-bundle
cd UserManagementAdd this in your Gemfile :
gem 'smart_listing', github: 'GCorbel/smart_listing', branch: 'refactoring'
gem 'smart_managing'Run this command to download the gem with Bundler :
bundle installInstall SimpleForm by typing this command :
rails generate simple_form:installInstall SmartManaging by running this command :
rails generate smart_managing:installCreate a new model, for example :
rails generate model User name email age:integer
rake db:migrateEdit the config/routes.rb and add :
resources :usersOpen the file app/assets/javascripts/application.js and, before //= require_tree ., add this :
//= require bootstrap
//= require smart_listing
Rename the file app/assets/stylesheets/application.css to app/assets/stylesheets/application.css.scss and, at the bottom of the file, add this :
@import "bootstrap-sprockets";
@import "bootstrap";Create a file named app/controllers/users_controller.rb and add this :
class UsersController < ApplicationController
include SmartManaging::ControllerHelpers
# ... Your code
endFor a more simple controller, you can use inherited_resources but it's not mandatory.
Done! You can start the application by running rails server and go to http://localhost:3000.
Customize the managers
You can change the behavior of the SmartManaging for a specific model by creating a directory app/managers and a manager object. For exemple, you can have the file user_manager.rb which contain :
class UserManager < SmartManaging::Base
def editable_attributes
['name']
end
def attributes
['name', 'email']
end
endThis will show only the names and emails and allow to edit only the names.
A manager class must inherited from SmartManaging::Base and override his methods, for the complete list of overrideable methods, you can check this file.
You can specify a manager in the controller by overriding the manager method. For example, you can do this :
def manager
@manager ||= CustomManager.new(self)
end