fror = flex + ruby on rails
Устанавливаем ror + необходимые gems (sqlite3-ruby)
создадим где-нибудь скелет ror приложения (назовем его images):
> ruby images
исправим config/database.yml
development:
adapter: sqlite3
dbfile: db/images_development
test:
adapter: sqlite3
dbfile: db/images_test
production:
adapter: sqlite3
dbfile: db/images_production
и сгенерируем модель и контроллер:
> ruby scriptgenerate model image
> ruby scriptgenerate controller image
app/controllers/image_controller.rb
class ImageController < ApplicationController
def list
@images=Image.find :all
render :xml => @images.to_xml
end
end
создадим базутаблицу и добавим данные:
db/migrate/001_create_images.rb
class CreateImages < ActiveRecord::Migration
def self.up
create_table :images do |t|
t.column :filename, :string
end
end
def self.down
drop_table :images
end
end
> ruby scriptconsole
>> Image.new(:filename=>"1/1.jpg").save
=> true
config/routes.rb должен содержать:
ActionController::Routing::Routes.draw do |map|
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id'
end
запустим сервер:
> ruby scriptserver
и проверим работу приложения:
http://localhost:3000/image/list
получим:
<?xml version="1.0" encoding="UTF-8"?>
<images>
<image>
<id type="integer">1</id>
<filename>1/1.jpg</filename>
</image>
</images>
fror0.jpg
С ror теперь закончили. Приступим к flex )
flex позволяет генерировать .swf файлы из описания в xml
установим Adobe Flex Builder 2.0 Beta 3 и создадим mxml application
images.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="imageRequest.send()" layout="absolute" width="473" height="326">
<mx:HTTPService method="POST" url="http://localhost:3000/image/list" id="imageRequest" useProxy="false" showBusyCursor="true"/>
<mx:DataGrid width="453" height="272" dataProvider="{imageRequest.lastResult.images.image}" editable="false" x="10" y="10">
<mx:columns>
<mx:DataGridColumn headerText="Filename" dataField="filename"/>
</mx:columns>
</mx:DataGrid>
<mx:Button click="imageRequest.send()" label="show me!" x="10" y="290"/>
</mx:Application>
запустим (Ctrl+F11):
fror1.jpg
продолжение следует…
Источник: coldfire.org.ua
К началу статьи