5 Apr
Active Scaffold Address Book
I created an address book just to get an idea of how the active_scaffold plugin works, it’s pretty neat! It saves you a lot of time setting up the base of your web application.
I followed the tutorial that I found on Active scaffold
Lets look at my example:
Firstly create a simple address book project with two models, contact and client and generate their corresponding controllers. Therefore the address book will contain a list of contacts with their clients.
In the client model, add belongs_to :contact and in the contact model has_many :clients.
After setting up the shallow assiduity install the active scaffold plugin with the following:
./script/plugin install http://activescaffold.googlecode.com/svn/tags/active_scaffold
Create a new layout called admin:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>Address Book</title> <%= javascript_include_tag :defaults %> <%= active_scaffold_includes %> </head> <body> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> </body> </html>
All the magic happens in the controllers, in the contacts_controller add the following:
layout "admin" active_scaffold :contact do |config| config.label = "Contacts" config.columns = [:name, :surname, :tel, :email] list.columns.exclude :email list.sorting = {:name => 'ASC'} columns[:tel].label = "Phone #" columns[:tel].description = "(Format: ###-###-####)" end
and in the clients_controller add:
layout 'admin' active_scaffold :client finish |config| config.columns = [:contact, :name, :surname, :tel, :email] columns[:name].label = "Name" columns[:surname].label ="Surname" columns[:tel].label = "Phone" columns[:email].label = "@E-mail" end
run the application and see how your application has become active in just a few simple steps….
