Active_scaffold_presentation is a project mainly written in RUBY and JAVASCRIPT, it's free.
Active Scaffold Presentation for RubyNation
In this phase we'll create a simple scaffold with a single field.
Connect to working directory: cd Workspaces
Create a new Rails project: sudo rails camur sudo chown -R medined:medined camur
Connect to project directory: cd camur
install plugins: script/plugin install git://github.com/lackac/render_component.git -r rails-edge script/plugin install git://github.com/activescaffold/active_scaffold.git
Create Person model: script/generate model person name:string
Execute the migration: rake db:migrate
Create the Person controller: script/generate controller person
Edit app/controllers/person_controller.rb: class PersonController < ApplicationController layout 'default' active_scaffold :person end
Create a default layout: cp ../camur_backup/app/views/layouts/default.erb app/views/layouts
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html;. charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<title>Presentation</title>
<%= stylesheet_link_tag "style" %>
<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>
</head>
<body id="page">
<div id="container">
<div id="header">
<h1>CAMUR</h1>
</div>
<div id="content">
<%= yield -%>
</div>
<div id="sidebar"></div>
</div>
</body>
</html>
Start a server in a new terminal. script/server
Visit person page. http://localhost:3000/person
12, Review the show create, edit, show, search, delete options.
This phase of the project will use nearly all of the datatypes that ActiveScaffold supports.
Create a Book model (all datatypes except for binary) script/generate model book person_id:integer name:string pages:integer price:float invoiced_at:datetime purchased_on:date paid_at:timestamp checkin:time description:text paperback:boolean
Create a controller for Book. script/generate controller book
Update the database. rake db:migrate
Edit app/models/book.rb to add relation to person. belongs_to :person
edit app/models/person.rb to add relation to books. has_many :books
Create app/controllers/book_controller.rb class BookController < ApplicationController layout 'default' active_scaffold :book end
start a server in a new terminal unless it is running script/server
visit book page. http://localhost:3000/book
Create and edit a book. You'll see too many fields and the order is uncontrolled. The 'person' field should be titled 'Owners'.
Edit app/controllers/book_controller.rb to hide some of the book fields and rename 'person' to 'Owner'. active_scaffold :book do |config| config.create.columns = [ :name, :paperback, :price ] config.columns[:person].label = "Owner" end
Reload the book page. Notice the server does not need to be restarted. Check out the column sorting.
Create some books. Normally, I'd create a rake task to initialize test data. Assign two books to David.
Visit the person page. Notice that the books show as a comma-delimited list. Click on the list and you'll see the sub-form pop open.
http://localhost:3000/person
The field order is not good. Edit app/controllers/person_controller.rb to fix this. We'll change the date format later. class PersonController < ApplicationController layout 'default' active_scaffold :person do |config| config.list.columns = [ :name, :books, :updated_at ] end end
Click edit. Notice the option to select an existing book or enter a new one. And that the person form has only a name field, all the other fields are book fields.
Edit app/controllers/person_controller.rb to restrict user to only existing books. Note the plural needs to be used. active_scaffold :person do |config| config.columns[:books].form_ui = :select end
Reload person page. Edit a person. Associate books to person. Since a book belongs_to a person, once it has been assigned it can't be assigned to another person.
Click on books link, show subform.
Too many fields in subform. Edit app/controllers/book_controller.rb to restrict the list fields. active_scaffold :book do |config| config.list.columns = [ :name, :description, :paperback, :price, :updated_at ] end
Reload and click on books link. Notice fewer columns.
Let's prevent book deletion. Edit app/controllers/book_controller.rb def delete_authorized? false end
Reload and click on books link. Notice the delete link is gone.
Time to fix the problem of ugly dates. There are several options but we'll add a new function to the ActiveSupport::TimeWithZone class.
Edit app/controllers/application.rb. class ActiveSupport::TimeWithZone def format_short_date self.strftime("%m/%d/%Y") end end
Create a app/helpers/person_helpers.rb file. module PersonHelper def updated_at_column(record) if record.updated_at.respond_to? :format_short_date record.updated_at.format_short_date else record.updated_at end end end
Edit app/helpers/person_helpers.rb by changing module to class to demonstrate an error.
Visit both the Person and Books pages to show that the helper module is loaded for both controllers.
Edit app/controllers/application.rb to comment out the 'helper :all' line.
Reload the Books page to see that the helper module is no longer loaded.
Edit app/controllers/PersonController.rb to add the following line after the layout is defined.
helper :person
Now the updated_at field on the Person page is different from the Book page.
Install the CalendarDateSelect gem. sudo gem install calendar_date_select
Add the following line immediately before the last end in config/environmnet.rb config.gem "calendar_date_select"
Restart the server.
Edit app/views/layouts/default.erb. Add the following line before the closing HEAD tag. <%= calendar_date_select_includes "silver" %>
5, Load the Book page. Click edit and look at the InvoicedAt field.
!!!!!!!!!!!!!!!! Create a custom scaffold of Paperback books.
git push origin master