| By Christophe Coenraets | Article Rating: |
|
| July 20, 2006 02:30 PM EDT | Reads: |
47,645 |
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules:
- The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products.
- The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog.
In the administration module, we use Rails' simple scaffolding feature to automatically provide the default infrastructure to list, view, create, edit, and delete products. In the store module, we experiment with additional features:- Templates
- Filtering using AJAX
- Partial Page Templates
- Builder Templates
- Putting a Flex front-end on top of a Ruby on Rails application
Create the Flexstore Database
1. Create a database called "flexstore"
Open a command prompt, navigate to the bin directory of your MySQL Server installation, and type the following command:
mysqladmin -uroot create flexstore
2. Import the data
- Download flexstore.sql.zip at http://coenraets.com/tutorials/flexonrails/resources/flexstore.sql.zip
- Extract flexstore.sql into the bin directory of your MySQL Server installation
- Type the following command to import the data in the flexstore database:
mysql -uroot flexstore < flexstore.sql
1. Install Ruby
- Download the Ruby installer at http://rubyforge.org/frs/download.php/4174/ruby182-15.exe
- Run the installer. Accept all the default settings.
Type the following command in the c:\ruby directory:
gem install rails --remote --include-dependencies
Create the Administration Module
1. Create the Flexstore application
- Create a directory called Rails in c:\
- Type the following command in c:\rails:
rails flexstore
2. Configure the database for the flexstore application
- Edit database.yml in c:\rails\flexstore\config
- Set the database parameter to flexstore in the development, test, and production sections
Type the following command in c:\rails\flexstore
ruby script\generate controller
Admin
4. Create a model for the products
Type the following command in c:\rails\flexstore:
ruby script\generate model Product
5. Modify the admin controller to enable Rails' scaffolding
- Edit admin_controller.rb in c:\rails\flexstore\app\controllers
- Modify the class as shown in Figure 1.
- Start the WEBrick web server installed with Rails
Type the following command in c:\rails\flexstore:ruby script\server
- Open a browser and access the following URL:
http://localhost:3000/admin
7. Define a custom index action
- Edit admin_controller.rb in c:\rails\flexstore\app\controllers
- Define an index action as shown in Figure 2.
- Create a file name index.rhtml in c:\rails\flexstore\app\views\admin
- Edit index.rhtml as follows:
<html>
<head>
<title>Product List</title>
</head>
<body>
<table>
<tr>
<td>Name</td>
<td>Price</td>
</tr>
<% @products.each do |product| %>
<tr>
<td><%= link_to product.name, :action => "show", :id => product.id %></td>
<td align="right"><%= sprintf("$%0.2f", product.price) %></td>
</tr>
<% end %>
</table>
<p><%= link_to "Create new product", :action => "new" %></p>
</body>
</html>
9. Test the application. Open a browser and access the following URL:
http://localhost:3000/admin
10. Validation
- Edit product.rb in c:\rails\flexstore\app\models
- Modify the class as shown in Figure 3.
Create the Store Module
1. Deploy the product images and the flexstore stylesheet
- Download assets.zip at http://coenraets.com/tutorials/flexonrails/resources/assets.zip.
- Extract assets.zip in c:\rails\flexstore\public.
Type the following command in c:\rails\flexstore:
ruby script\generate controller Store
3. Define an index action in the Store controller
- Edit store_controller.rb in c:\rails\flexstore\app\controllers
- Define an index action as shown in Figure 4.
- Create a file name index.rhtml in c:\rails\flexstore\app\views\store
- Edit index.rhtml as follows:
<html>
<head>
<title>Flexstore on Rails</title>
<%= stylesheet_link_tag "flexstore", :media => "all" %>
</head>
<body>
<!-- begin catalog -->
<div id="catalog">
<% for product in @products %>
<!-- begin thumbnail -->
<div class="thumbnail">
<strong><%= product.name %></strong>
<img src="<%= product.image %>"/>
<div>
<font color="#CC6600"><b><%= sprintf("$%0.2f", product.price) %></b></font>
<p>
<%= product.camera==1?'Camera<br />':'' %>
<%= product.video==1?'Video<br />':'' %>
<%= product.triband==1?'Triband':'' %>
</p>
</div>
</div>
<!-- end thumbnail -->
<% end %>
</div>
<!-- end catalog -->
</body>
</html>
5. Test the application
Open a browser and access the following URL:
http://localhost:3000/store
Published July 20, 2006 Reads 47,645
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Christophe Coenraets
Christophe Coenraets currently works as a Senior Technical Evangelist at Adobe. Before joining Adobe, Christophe was an evangelist at Macromedia, focusing on Rich Internet Applications and Enterprise integration. Prior to Macromedia, Christophe was the head of Java and J2EE Technical Evangelism at Sybase, where he started working on Java Enterprise projects in 1996. Before joining Sybase in the US, Christophe held different positions at Powersoft in Belgium, including Principal Consultant for PowerBuilder, and Manager of the Professional Services organization. Before joining Powersoft, Christophe worked as a developer and architect on several retail and BPM projects. Christophe has been a regular speaker at conferences worldwide for the last 10 years.
![]() |
newgen315 09/09/08 01:42:18 PM EDT | |||
Hi, |
||||
![]() |
SYS-CON Australia News Desk 07/20/06 02:45:34 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
Web Developer's & Designer's Journal 07/20/06 02:00:15 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
SYS-CON Australia News Desk 07/11/06 05:06:58 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
SYS-CON Brazil News Desk 07/11/06 04:53:01 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
Paul Blackburn 07/11/06 04:08:45 PM EDT | |||
I enjoyed your tutorial, but have a little problem with it. Everything worked until the Flex part. I get an error msessage like this: "Error: 'FABridge.store' is null or not an object" Thanks |
||||
![]() |
Web Developer's & Designer's Journal 05/22/06 04:19:09 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
SYS-CON Italy News Desk 05/19/06 10:54:06 AM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
SYS-CON Australia News Desk 05/19/06 07:46:21 AM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
AJAX News Desk 05/18/06 06:42:12 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
SYS-CON India News Desk 05/18/06 06:18:23 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
![]() |
SYS-CON News Desk 05/18/06 05:36:13 PM EDT | |||
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules: The administration module is an internal application used to maintain the product database. You use the administration module to create, update, and delete products. The store module is a customer-facing application. Customers use the store module to browse and filter the product catalog. |
||||
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Ph.D. in Twitter Anyone?
- Adobe Flex Developer Earns $100K in New York City
- Eolas Sues the Internet
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Special Report on the Emerging Cloud Computing Trend
- My Thoughts on Ulitzer
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Ulitzer Live! New Media Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Software Flexibility in the Cloud - Part 4 of 5
- Is Microsoft as Free as Open Source?
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Where Are RIA Technologies Headed in 2008?
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe/Macromedia - Microsoft, Look Out!
- How To Create a Photo Slide Show ...
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets




































