Flex
Adobe Flex: Flexstore on Rails Tutorial
Flexstore is a traditional Shopping Cart application. In this tutorial, we create two modules
Jul. 20, 2006 02:30 PM
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
This tutorial uses a MySQL database. It is assumed that you already have MySQL up and running.
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
Install Ruby and Rails1. Install Ruby
2. Install Rails
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
3. Create a controller for the administration module
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.
6. Test the application
Rails' scaffolding defined in the Admin controller automatically provides default actions and views to list, view, create, edit and delete products. Each of these actions and views can be overwritten. We overwrite the default index action in the next steps.
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.
8. Create the view for the index action
- 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.
11. Test the application again. Try to add a product without a name or with a non numeric price value.
Create the Store Module
1. Deploy the product images and the flexstore stylesheet
2. Create a controller for the administration module
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.
4. Create the view for the index action
- 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
About Christophe CoenraetsChristophe 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.
#12 |
Hi,
Where would be the sql files mentioned in the article. I look all over for them and would appreciate a link
|
#11 |
SYS-CON Australia News Desk commented on 20 Jul 2006
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.
|
#10 |
Web Developer's & Designer's Journal commented on 20 Jul 2006
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.
|
#9 |
SYS-CON Australia News Desk commented on 11 Jul 2006
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.
|
#8 |
SYS-CON Brazil News Desk commented on 11 Jul 2006
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.
|
#7 |
Paul Blackburn commented on 11 Jul 2006
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
|
#6 |
Web Developer's & Designer's Journal commented on 22 May 2006
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.
|
#5 |
SYS-CON Italy News Desk commented on 19 May 2006
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.
|
#4 |
SYS-CON Australia News Desk commented on 19 May 2006
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.
|
#3 |
AJAX News Desk commented on 18 May 2006
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.
|
#2 |
SYS-CON India News Desk commented on 18 May 2006
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.
|
#1 |
SYS-CON News Desk commented on 18 May 2006
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.
|