---
title: "Restfulx + Rails开发flex应用"
author: "taito"
date: "2010-05-28T10:56:11Z"
tags: []
categories: ["Web前端"]
slug: "restfulx-rails-flex"
draft: false
lastmod: "2010-05-28T10:58:17Z"
id: 677645
url: "https://taito.iteye.com/blog/677645"
---

需要以下开发环境

1. Ruby on Rails 2.1+ (这里用的是2.3.5!)
2. Flex SDK 3.0+
3. MySQL 5.0+

在开始之前必须确定你的系统path正确指向到了Adobe Flex Sdk目录下

 

- On OS X it’s typically `/Applications/Adobe Flex Builder 3/sdks/3.x.x/bin`
- On Win32 it’s `C:\Program Files\Adobe\Flex Builder 3\sdks\3.x.x\bin`

(以下是在win32环境下)。

首先创建你的项目

```
gem install restfulx


rails -d mysql demo


cd demo
```

 

 

 

编辑config/environment.rb并添加

 

```
config.gem "restfulx" 
```

 

 

配置你的config/database.yml 文件

 

   将数据库连接,设置为正确的方式，配置其用户名和密码

 

运行

 

```
ruby script\generate rx_config
```

 

创建 db\\model.yml文件

 

```
location:


  - name: string


  - notes: text


  - belongs_to: [user]


  - has_many: [tasks]





project:


  - name: string


  - notes: text


  - start_date: date


  - end_date: date


  - completed: boolean


  - belongs_to: [user]


  - has_many: [tasks]





task:


  - name: string


  - notes: text


  - start_time: datetime


  - end_time: datetime


  - completed: boolean


  - next_action: boolean


  - belongs_to: [project, location, user]





note:


  - content: text


  - belongs_to: [user]





user:


  - login: string


  - first_name: string


  - last_name: string


  - email: string


  - has_many: [tasks, projects, locations]


  - has_one: [note]
```

 

 

运行以下应用

 

```
ruby script\generate rx_yaml_scaffold


rake db:refresh


rake rx:flex:build


ruby script\server
```

 

 

可以看看效果了[.](http://www.uiok.net)

 

http://localhost:3000

 

 

======================

如何切换为AIR应用

 

```
ruby script\generate rx_config -a


rake rx:air:build


rake rx:air:run

```

 

 

如何切换回Flex应用

 

```
ruby script\generate rx_config
```

 

![](http://dl.iteye.com/upload/attachment/255966/f845415f-a527-30ee-b414-029a37f6b2d0.jpg)

R Link:

 

[http://restfulx.github.com/](http://restfulx.github.com/)