RestfulX導入記 -その1-
Flex + Railsの連携があまりに面倒だったので,フレームワークを探す.
そこで見つけたのが,Ruboss
が,Rubossはいくらやっても上手くいかず.
って,Restfulxに名前が変わってたのね.
ということで,本当に5分でFlex+Railsのアプリ雛形ができたので,これから奮闘していこうかと思います.
詳しくはこちらを参照すれば良いらしい
http://restfulx.github.com/
http://wiki.github.com/dima/restfulx
http://wiki.github.com/dima/restfulx/getting-started-with-restfulx-and-ruby-on-rails
を見ながら
チュートリアルの通りに叩きました.
まずは,環境の確認です.
1. Ruby on Rails 2.1+
2. Flex SDK 3.0+
3. MySQL 5.0+
で,大丈夫.
mxmlcなんかが入っているFlex3 SDKにパスを通さないといけません.macosxの場合は
vi .bash_profile
を開いて
export $PATH=$PATH:/Applications/AdobeFlexBuilder3/sdks/3.1.0/bin
なんてしときます.
ちなみに,半角スペースが面倒だったので,リネームしました.
次に,プロジェクトを作成し,restfulxをインストール
で,config/environment.rbに
config.gem "restfulx"
を追記.configを作成.
./script/generate rx_config
次に,scaffold用のmodel設定ファイルを記述.
今まで,shellを書いていたのが,設定ファイルになったのでGJ.
しかも,has_manyなんかも設定できたりします.
db/model.ymlに
project:
- name: string
- notes: text
- start_date: date
- end_date: date
- completed: boolean
- belongs_to: [user]
- has_many: [tasks]location:
- name: string
- notes: text
- 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]
をコピペして,scaffoldを実行します.
./script/generate rx_yaml_scaffold
DBとテーブルを生成
rake db:refresh
最後にFlex用のプロジェクトを自動生成します.
rake rx:flex:build
あとは,サーバを起動して,localhost:3000とかにアクセスすればOK.
神!!!