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!
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
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide
- The Italian Army Switches to LibreOffice
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Petros Koutoupis' RapidDisk
- Linux Mint 18
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Varnish Software's Varnish Massive Storage Engine
- Privacy and the New Math
- Ben Rady's Serverless Single Page Apps (The Pragmatic Programmers)