integrating flex and rails with ruby amf
TRANSCRIPT
![Page 1: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/1.jpg)
Flex and Rails with RubyAMF
Tony HillersonSoftware ArchitectEffectiveUIRailsConf
![Page 2: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/2.jpg)
Code and Slides:http://github.com/thillerson/preso_code/
![Page 3: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/3.jpg)
Sample du Jour: Stuff
![Page 4: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/4.jpg)
![Page 5: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/5.jpg)
Why Flex and Rails?
They Make The Great Tag Team!
![Page 6: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/6.jpg)
[SKIP INTRO]
![Page 7: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/7.jpg)
What are the Options?
![Page 8: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/8.jpg)
XML
![Page 9: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/9.jpg)
XML is the Default Option
![Page 10: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/10.jpg)
# POST /contexts# POST /contexts.xmldef create @context = Context.new(params[:context]) respond_to do |format| if @context.save flash[:notice] = 'Context was successfully created.' format.html { redirect_to(@context) } format.xml { render :xml => @context, :status => :created, :location => @context } else format.html { render :action => "new" } format.xml { render :xml => @context.errors, :status => :unprocessable_entity } end endend
![Page 11: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/11.jpg)
JSON
Javascript Object Notation
![Page 12: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/12.jpg)
JSON is in Rails Tooformat.json { render :json => @context.to_json }
http://as3corlib.googlecode.com
var obj:Object = JSON.decode(jsonString)
![Page 13: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/13.jpg)
AMF
Action Message Format
![Page 14: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/14.jpg)
AMF is the Good Stuff
Buck Thinks it’s Great!
![Page 15: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/15.jpg)
RubyAMF
http://rubyamf.orghttp://rubyamf.googlecode.com
![Page 16: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/16.jpg)
Installing RubyAMF$ script/plugin install http://rubyamf.googlecode.com/svn/current/rubyamf
• New File: app/controllers/rubyamf_controller.rb• New File: config/rubyamf_config.rb• config/initializers/mime_types.rb modified: Mime::Type.register "application/x-amf", :amf• config/routes.rb modified: ActionController::Routing::Routes.draw do |map| map.rubyamf_gateway 'rubyamf_gateway', :controller => 'rubyamf', :action => 'gateway' end
![Page 17: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/17.jpg)
Con"guring RubyAMFmodule RubyAMF module Configuration ClassMappings.translate_case = true ClassMappings.assume_types = false ParameterMappings.scaffolding = true ClassMappings.register( :actionscript => 'Task', :ruby => 'Task', :type => 'active_record', #:associations => ["context"], :attributes => ["id", "label", "context_id", "completed_at", "created_at", "updated_at"]) endend
![Page 18: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/18.jpg)
Con"guring RubyAMFClassMappings.translate_case = false
public var created_at:Date;
ClassMappings.translate_case = true
public var createdAt:Date; // created_at in rails
![Page 19: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/19.jpg)
Con"guring RubyAMFClassMappings.assume_types = true
class Context < ActiveRecord::Base
[RemoteClass(alias="Context")]public class Context {
matches
for free
![Page 20: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/20.jpg)
Con"guring RubyAMFClassMappings.assume_types = false
class Context < ActiveRecord::Base
[RemoteClass(alias="Context")]public class Context {
matches
ClassMappings.register( :actionscript => 'Context', :ruby => 'Context', :type => 'active_record', :attributes => ["id", ...])
with registration
![Page 21: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/21.jpg)
Con"guring RubyAMFParameterMappings.scaffolding = false
save(context);def save @context = params[0]becomes
ParameterMappings.scaffolding = true
save( {context:context});
def save @context = params[:context]becomes
![Page 22: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/22.jpg)
Connecting to Rails via RubyAMF
<mx:RemoteObject id="contextsService" destination="rubyamf" endpoint="http://localhost:3000/rubyamf_gateway/" source="ContextsController" showBusyCursor="true"/>public function save(context:Context):void { var call:AsyncToken =
contextsService.save({context:context}); call.addResponder(responder);}
![Page 23: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/23.jpg)
Development Work#ow
![Page 24: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/24.jpg)
1. Generate and Migrate$ script/generate rubyamf_scaffold context label:string
$ rake db:migrate
class CreateContexts < ActiveRecord::Migration def self.up create_table :contexts do |t| t.string :label t.timestamps end end
def self.down drop_table :contexts endend
![Page 25: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/25.jpg)
def load_all @contexts = Context.find :all respond_to do |format| format.amf { render :amf => @contexts } end end def save respond_to do |format| format.amf do if params[:context].save render :amf => params[:context] else render :amf =>
FaultObject.new(params[:context].errors.join("\n")) end end end end
![Page 26: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/26.jpg)
2. Sample Datawork: id: 1 label: Work
home: id: 2 label: Home
anarco_syndicalist_commune_biweekly_meetings: id: 3 label: Anarcho-syndicalist Commune Bi-weekly Meetings
![Page 27: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/27.jpg)
3. Test
class ContextTest < ActiveSupport::TestCase def test_context_without_label_fails non_label_context = Context.new assert !(non_label_context.save) error_messages = non_label_context.errors.on(:label) assert !(error_messages.empty?) end
class Context < ActiveRecord::Base validates_presence_of :label
![Page 28: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/28.jpg)
4. Con"gure
ClassMappings.register( :actionscript => 'Context', :ruby => 'Context', :type => 'active_record', #:associations => ["tasks"], :attributes => ["id", "label", "created_at", "updated_at"])
![Page 29: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/29.jpg)
5. Wire<mx:RemoteObject id="contextsService" destination="rubyamf" endpoint="http://localhost:3000/rubyamf_gateway/" source="ContextsController" showBusyCursor="true"/>
<mx:RemoteObjectid="tasksService"
destination="rubyamf" endpoint="http://localhost:3000/rubyamf_gateway/" source="TasksController" showBusyCursor="true"/>
![Page 30: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/30.jpg)
5. Wirepublic function loadAll():void { var call:AsyncToken = service.load_all(); call.addResponder(responder);}
public function save(context:Context):void { var call:AsyncToken =
service.save({context:context}); call.addResponder(responder);}
public function destroy(context:Context):void { var call:AsyncToken =
service.destroy({id:context.id}); call.addResponder(responder);}
![Page 31: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/31.jpg)
5. Wirepublic function execute(event:CairngormEvent):void { var evt:SaveContextEvent = event as SaveContextEvent; var delegate:ContextsDelegate = new ContextsDelegate(this); delegate.save(evt.context);}
public function result(data:Object):void { var result:ResultEvent = data as ResultEvent; var context:Context = result.result as Context; ...}
![Page 32: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/32.jpg)
X. Rinse and Repeat
![Page 33: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/33.jpg)
The Future
![Page 34: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/34.jpg)
GemPlugin + GemC Extension
![Page 35: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/35.jpg)
GemPlugin
C Extension
![Page 36: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/36.jpg)
![Page 37: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/37.jpg)
An Impassioned Plea
![Page 38: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/38.jpg)
Resources:
http://rubyamf.googlecode.comhttp://groups.google.com/group/rubyamfhttp://github.com/thillerson/rubyamf
![Page 39: Integrating Flex And Rails With Ruby Amf](https://reader033.vdocuments.mx/reader033/viewer/2022052823/55567227d8b42a144c8b51c7/html5/thumbnails/39.jpg)
Thanks!Tony Hillersonhttp://slideshare.com/thillersonhttp://github.com/thillersonhttp://thillerson.blogspot.comhttp://effectiveui.com
Twitter: thillersonBrightkite: thillerson
39
You
YourFather
Bob