Improved Scaffolding for Ruby on Rails
Let's begin by fixing the order of our columns. Change the app/controllers/player_controller.rb file to look like this:
class PlayerController < ApplicationController
active_scaffold :player do |c|
c.columns = [:name, :squad, :address,
:date_of_birth,
:contact_tel_no, :condition ]
c.columns[:squad].ui_type = :select
c.columns[:condition].ui_type = :select
end
end
In this code, we provide a configuration code block to the activescaffold method where we specify the ordering of the columns, in addition to setting the ui_type associated with the squad and condition data to be :select. This fixes our ordering issue and sets the squad and condition selection mechanism to a standard drop-down list.
Sorting out the date problem requires the creation of a Rails helper method for the players table. Edit the app/helpers/player_helper.rb file, and add the following code:
module PlayerHelper
def date_of_birth_form_column(record, input_name)
date_select :record, :date_of_birth,
:name => input_name,
:start_year => 1990
end
end
The oddly named date_of_birth_form_column helper method calls the ActiveScaffold-supplied date_select method, which lets us adjust the earliest start date associated with our date_of_birth data. With these changes made, restart the Rails application and reload the browser window. Figure 3 shows the new-and-improved player listing, and Figure 4 shows the final version of our player data-entry form. As I'm sure you'll agree, both screens look the business. Take time to play around with the added functionality that ActiveScaffold has provided for free, including sort-ordering links on each of the column headings.
To learn more about Rails, I highly recommend Agile Web Development with Rails by The Pragmatic Programmers (now in its second edition, with a third due soon), as well as O'Reilly Media's Rails Cookbook. To learn more about ActiveScaffold, check out the well-written documentation and code examples available on-line at the ActiveScaffold Web site (see Resources). As I hope this article demonstrates, it doesn't take much to turn an ugly, default Rails application into something you just might want to show off!
Resources
Ruby on the Web: www.ruby-lang.org
The RubyGems RubyForge repository: rubyforge.org/projects/rubygems
ActiveScaffold Web Site: activescaffold.com
Rails Plugin Repository: agilewebdevelopment.com/plugins
“An Ajax-Enhanced Web-Based Ethernet Analyzer” by Paul Barry (LJ, May 2007): www.linuxjournal.com/article/9614
“A Database-Driven Web Application in 18 Lines of Code” by Paul Barry (LJ, March 2005): www.linuxjournal.com/article/7937
Reuven Lerner's Excellent Series of Articles Comparing PostgreSQL to MySQL (April, May and June 2007 issues of LJ): www.linuxjournal.com/article/9571, www.linuxjournal.com/article/9618 and www.linuxjournal.com/article/9649
Paul Barry (paul.barry@itcarlow.ie) lectures at the Institute of Technology, Carlow in Ireland. Find out more about the stuff he does at this Web site: glasnost.itcarlow.ie/~barryp.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Web Development News
Developer Poll
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Home, My Backup Data Center
- A Topic for Discussion - Open Source Feature-Richness?
- What's the tweeting protocol?
- Dart: a New Web Programming Experience
- Developer Poll
- Trying to Tame the Tablet
- Reply to comment | Linux Journal
1 hour 49 min ago - Reply to comment | Linux Journal
4 hours 21 min ago - Reply to comment | Linux Journal
5 hours 39 min ago - great post
6 hours 14 min ago - Google Docs
6 hours 36 min ago - Reply to comment | Linux Journal
11 hours 25 min ago - Reply to comment | Linux Journal
12 hours 11 min ago - Web Hosting IQ
13 hours 45 min ago - Thanks for taking the time to
15 hours 22 min ago - Linux is good
17 hours 20 min ago










Comments
Some of RoR examples
Some of RoR examples that i do
Ruby On Rails installation on Windows
Ruby on Rails installation in Ubuntu
autocompleter example in RoR
live Validation for RoR
Ismail Muhammad Noman
share-facts.blogspot.com
Getting the article code to work with PostgreSQL.
A reader, Ken Shaffer, emailed with an issue he had getting the example code (above) to work with his version of PostgreSQL. I initially suggested he try it with MySQL just to get things going but, to Ken's credit, he soldiered on and sorted out his problems. Here's a copy of Ken's e-mail to me letting me know what he did. Both Ken and I hope this information will be of use to other readers experiencing similar problems.
----------- start of Ken's email -----------
Hi Paul,
I did succeed in getting a compatible set of gems and activescaffold
for running the soccer club demo. Open source is so dynamic
that it's sometimes tricky getting compatible versions of things --
my hat's off to the people putting Linux distributions together.
For the Ubuntu 8.10 rails 2.1 (rake, rubygems) installed via the
Synaptic Package Manager, use the ruby_pg gem instead of the postgres
gem.
I understand the postgres gem has not been supported since 2006.
Also avoid the pg gem, which is not necessary. The activescaffold
install now needs to pick out the rails 2.1 (previous) version.
The following failed to get the rails 2.1 version (got the default 2.2
ver):
script/plugin install \
git://github.com/activescaffold/active_scaffold.git \
-r rails-2.1
Found a code snippit (attached below) which worked.
Another (more painful) approach which worked is to update all the
rails 2.1.0 versions to the 2.2.2 versions (and also update rubygems).
The default activescaffold install will then work.
The below code snippit succeeded in getting the activescaffold version
compatible with rails 2.1
from http://code.google.com/p/activescaffold/issues/detail?id=626
Comment 1 by mr.gaffo, Nov 18, 2008
---snip -----
Either (in vendor plugin):
git clone git://github.com/activescaffold/active_scaffold.git
[cd to active_scaffold ]
git checkout origin/rails-2.1
rm -rf .git
Or, pull down the newest rails-2.1 tarball from github.
--snip------
Again, thanks for a great article. It was the combination of postgresql
and rails that caught my interest. Feel free to pass along any info, no
attribution needed.
Ken
----------- end of Ken's email -----------
Thanks for that, Ken!
Paul.
Paul Barry