SlideShare a Scribd company logo
1 of 39
Download to read offline
Flex and Rails   Tony Hillerson
                  Software Architect

with RubyAMF      EffectiveUI
                  RailsConf
Code and Slides:
http://github.com/thillerson/preso_code/
Sample du Jour: Stuff
Why Flex and Rails?

They Make The
Great Tag Team!
[SKIP INTRO]
What are the Options?
XML
XML is the Default
     Option
# POST /contexts
# POST /contexts.xml
def 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 => quot;newquot; }
      format.xml {
         render :xml => @context.errors,
         :status => :unprocessable_entity }
    end
  end
end
JSON

Javascript Object Notation
JSON is in Rails Too
format.json { render :json => @context.to_json }


        http://as3corlib.googlecode.com


   var obj:Object = JSON.decode(jsonString)
AMF

Action Message Format
AMF is the Good Stuff

Buck Thinks it’s Great!
RubyAMF


       http://rubyamf.org
http://rubyamf.googlecode.com
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 quot;application/x-amfquot;, :amf

  • config/routes.rb modified:
    ActionController::Routing::Routes.draw do |map|
        map.rubyamf_gateway 'rubyamf_gateway',
          :controller => 'rubyamf', :action => 'gateway'
    end
Con guring RubyAMF
module RubyAMF
  module Configuration
    ClassMappings.translate_case = true
    ClassMappings.assume_types = false
    ParameterMappings.scaffolding = true
    ClassMappings.register(
      :actionscript => 'Task',
      :ruby          => 'Task',
      :type          => 'active_record',
      #:associations => [quot;contextquot;],
      :attributes    => [quot;idquot;, quot;labelquot;, quot;context_idquot;,
         quot;completed_atquot;, quot;created_atquot;, quot;updated_atquot;])
  end
end
Con guring RubyAMF
ClassMappings.translate_case = false

public var created_at:Date;


ClassMappings.translate_case = true

public var createdAt:Date; // created_at in rails
Con guring RubyAMF
  ClassMappings.assume_types = true

  class Context < ActiveRecord::Base
              matches
   [RemoteClass(alias=quot;Contextquot;)]
   public class Context {

               for free
Con guring RubyAMF
  ClassMappings.assume_types = false

  class Context < ActiveRecord::Base
              matches
   [RemoteClass(alias=quot;Contextquot;)]
   public class Context {

          with registration
  ClassMappings.register(
    :actionscript => 'Context',
    :ruby          => 'Context',
    :type          => 'active_record',
    :attributes    => [quot;idquot;, ...])
Con guring RubyAMF
              ParameterMappings.scaffolding = false

                                       def save
                         becomes
     save(context);                      @context = params[0]


             ParameterMappings.scaffolding = true
                                       def save
save(
                                         @context =
                         becomes
   {context:context}
                                            params[:context]
);
Connecting to Rails via
       RubyAMF
<mx:RemoteObject
    	id=quot;contextsServicequot;
    	destination=quot;rubyamfquot;
    	endpoint=quot;http://localhost:3000/rubyamf_gateway/quot;
    	source=quot;ContextsControllerquot;
    	showBusyCursor=quot;truequot;
/>
public function save(context:Context):void {
	 	 var call:AsyncToken =
          contextsService.save({context:context});
	 	 call.addResponder(responder);
}
Development Work ow
1. Generate and Migrate
$ script/generate rubyamf_scaffold context label:string
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
  end
end
$ rake db:migrate
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(quot;nquot;))
      end
    end
  end
end
2. Sample Data
work:
  id: 1
  label: Work

home:
  id: 2
  label: Home

anarco_syndicalist_commune_biweekly_meetings:
  id: 3
  label: Anarcho-syndicalist Commune Bi-weekly Meetings
3. Test
class Context < ActiveRecord::Base
  validates_presence_of :label



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
4. Con gure

ClassMappings.register(
  :actionscript => 'Context',
  :ruby          => 'Context',
  :type          => 'active_record',
  #:associations => [quot;tasksquot;],
  :attributes    => [quot;idquot;, quot;labelquot;, quot;created_atquot;, quot;updated_atquot;])
5. Wire
<mx:RemoteObject
    	id=quot;contextsServicequot;
    	destination=quot;rubyamfquot;
    	endpoint=quot;http://localhost:3000/rubyamf_gateway/quot;
    	source=quot;ContextsControllerquot;
    	showBusyCursor=quot;truequot;
/>

<mx:RemoteObject
     id=quot;tasksServicequot;
     destination=quot;rubyamfquot;
    	endpoint=quot;http://localhost:3000/rubyamf_gateway/quot;
    	source=quot;TasksControllerquot;
    	showBusyCursor=quot;truequot;
/>
5. Wire
public 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);
}
5. Wire
public 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;
  ...
}
X. Rinse and Repeat
The Future
Gem
Plugin + Gem
 C Extension
Gem
   Plugin
C Extension
An Impassioned Plea
Resources:

http://rubyamf.googlecode.com
http://groups.google.com/group/rubyamf
http://github.com/thillerson/rubyamf
Your
                              Bob
                                        Father




                                         You




     Thanks!
     Tony Hillerson
     http://slideshare.com/thillerson
     http://github.com/thillerson
     http://thillerson.blogspot.com
     http://effectiveui.com

     Twitter: thillerson
     Brightkite: thillerson




39

More Related Content

What's hot

Introduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDBIntroduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDB
Adrien Joly
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
Juan Maiz
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
Jeremy Kendall
 

What's hot (19)

Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Javascript asynchronous
Javascript asynchronousJavascript asynchronous
Javascript asynchronous
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run them
 
node ffi
node ffinode ffi
node ffi
 
Introduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDBIntroduction to asynchronous DB access using Node.js and MongoDB
Introduction to asynchronous DB access using Node.js and MongoDB
 
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
[Quase] Tudo que você precisa saber sobre  tarefas assíncronas[Quase] Tudo que você precisa saber sobre  tarefas assíncronas
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyoエラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"Артем Яворский "Compile like it's 2017"
Артем Яворский "Compile like it's 2017"
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]
 
Any event intro
Any event introAny event intro
Any event intro
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 

Viewers also liked

The Information Advantage - Information Access in Tomorrow's Enterprise
The Information Advantage - Information Access in Tomorrow's EnterpriseThe Information Advantage - Information Access in Tomorrow's Enterprise
The Information Advantage - Information Access in Tomorrow's Enterprise
Elizabeth Lupfer
 
MRV Folder Fortune / Fortaleza - CE
MRV Folder Fortune / Fortaleza - CEMRV Folder Fortune / Fortaleza - CE
MRV Folder Fortune / Fortaleza - CE
MRV Engenharia
 
tamtan company profile
tamtan company profiletamtan company profile
tamtan company profile
sandy sandy
 

Viewers also liked (20)

Resurfacing
ResurfacingResurfacing
Resurfacing
 
The Information Advantage - Information Access in Tomorrow's Enterprise
The Information Advantage - Information Access in Tomorrow's EnterpriseThe Information Advantage - Information Access in Tomorrow's Enterprise
The Information Advantage - Information Access in Tomorrow's Enterprise
 
Top 10 Clues That Your Presentation Is Too Long
Top 10 Clues That Your Presentation Is Too LongTop 10 Clues That Your Presentation Is Too Long
Top 10 Clues That Your Presentation Is Too Long
 
Mercer: What's Working Research on Employee Engagement
Mercer: What's Working Research on Employee EngagementMercer: What's Working Research on Employee Engagement
Mercer: What's Working Research on Employee Engagement
 
Beyond Employee Engagement | @dalecarnegie
Beyond Employee Engagement | @dalecarnegieBeyond Employee Engagement | @dalecarnegie
Beyond Employee Engagement | @dalecarnegie
 
Focas bebês - Focas babies
Focas bebês - Focas babiesFocas bebês - Focas babies
Focas bebês - Focas babies
 
The Power of Peace
The Power of PeaceThe Power of Peace
The Power of Peace
 
How To Present
How To PresentHow To Present
How To Present
 
Global Warming
Global WarmingGlobal Warming
Global Warming
 
Relationships 2.0
Relationships 2.0Relationships 2.0
Relationships 2.0
 
Midwinter Holidays: Rebirth of Light
Midwinter Holidays:  Rebirth of LightMidwinter Holidays:  Rebirth of Light
Midwinter Holidays: Rebirth of Light
 
MRV Folder Fortune / Fortaleza - CE
MRV Folder Fortune / Fortaleza - CEMRV Folder Fortune / Fortaleza - CE
MRV Folder Fortune / Fortaleza - CE
 
Module05
Module05Module05
Module05
 
tamtan company profile
tamtan company profiletamtan company profile
tamtan company profile
 
Information Extraction and Linked Data Cloud
Information Extraction and Linked Data CloudInformation Extraction and Linked Data Cloud
Information Extraction and Linked Data Cloud
 
The Brand Train - Branding on the move
The Brand Train - Branding on the moveThe Brand Train - Branding on the move
The Brand Train - Branding on the move
 
ICEIM Conference, Durban, SA 2014 - Sudeep Krishnan, IIM Ahmedabad
ICEIM Conference, Durban, SA 2014 - Sudeep Krishnan, IIM AhmedabadICEIM Conference, Durban, SA 2014 - Sudeep Krishnan, IIM Ahmedabad
ICEIM Conference, Durban, SA 2014 - Sudeep Krishnan, IIM Ahmedabad
 
Module03
Module03Module03
Module03
 
Grafittis, Lenguaje Urbano
Grafittis, Lenguaje UrbanoGrafittis, Lenguaje Urbano
Grafittis, Lenguaje Urbano
 
Holiday Greetings
Holiday GreetingsHoliday Greetings
Holiday Greetings
 

Similar to Flex With Rubyamf

Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編
Masakuni Kato
 

Similar to Flex With Rubyamf (20)

All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
Rush, a shell that will yield to you
Rush, a shell that will yield to youRush, a shell that will yield to you
Rush, a shell that will yield to you
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Jicc teaching rails
Jicc teaching railsJicc teaching rails
Jicc teaching rails
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編浜松Rails3道場 其の四 View編
浜松Rails3道場 其の四 View編
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Sprockets
SprocketsSprockets
Sprockets
 

More from Tony Hillerson (11)

Totally Build Apps for Free! (not really)
Totally Build Apps for Free! (not really)Totally Build Apps for Free! (not really)
Totally Build Apps for Free! (not really)
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Dynamic Sound for Android
Dynamic Sound for AndroidDynamic Sound for Android
Dynamic Sound for Android
 
Git for Android Developers
Git for Android DevelopersGit for Android Developers
Git for Android Developers
 
Designing an Android App from Idea to Market
Designing an Android App from Idea to MarketDesigning an Android App from Idea to Market
Designing an Android App from Idea to Market
 
Rails on HBase
Rails on HBaseRails on HBase
Rails on HBase
 
SCM for Android Developers Using Git
SCM for Android Developers Using GitSCM for Android Developers Using Git
SCM for Android Developers Using Git
 
First Android Experience
First Android ExperienceFirst Android Experience
First Android Experience
 
iPhone Persistence For Mere Mortals
iPhone Persistence For Mere MortalsiPhone Persistence For Mere Mortals
iPhone Persistence For Mere Mortals
 
Flex Framework Smackdown
Flex Framework SmackdownFlex Framework Smackdown
Flex Framework Smackdown
 
Flex And Rails
Flex And RailsFlex And Rails
Flex And Rails
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Flex With Rubyamf

  • 1. Flex and Rails Tony Hillerson Software Architect with RubyAMF EffectiveUI RailsConf
  • 4.
  • 5. Why Flex and Rails? They Make The Great Tag Team!
  • 7. What are the Options?
  • 8. XML
  • 9. XML is the Default Option
  • 10. # POST /contexts # POST /contexts.xml def 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 => quot;newquot; } format.xml { render :xml => @context.errors, :status => :unprocessable_entity } end end end
  • 12. JSON is in Rails Too format.json { render :json => @context.to_json } http://as3corlib.googlecode.com var obj:Object = JSON.decode(jsonString)
  • 14. AMF is the Good Stuff Buck Thinks it’s Great!
  • 15. RubyAMF http://rubyamf.org http://rubyamf.googlecode.com
  • 16. 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 quot;application/x-amfquot;, :amf • config/routes.rb modified: ActionController::Routing::Routes.draw do |map| map.rubyamf_gateway 'rubyamf_gateway', :controller => 'rubyamf', :action => 'gateway' end
  • 17. Con guring RubyAMF module RubyAMF module Configuration ClassMappings.translate_case = true ClassMappings.assume_types = false ParameterMappings.scaffolding = true ClassMappings.register( :actionscript => 'Task', :ruby => 'Task', :type => 'active_record', #:associations => [quot;contextquot;], :attributes => [quot;idquot;, quot;labelquot;, quot;context_idquot;, quot;completed_atquot;, quot;created_atquot;, quot;updated_atquot;]) end end
  • 18. Con guring RubyAMF ClassMappings.translate_case = false public var created_at:Date; ClassMappings.translate_case = true public var createdAt:Date; // created_at in rails
  • 19. Con guring RubyAMF ClassMappings.assume_types = true class Context < ActiveRecord::Base matches [RemoteClass(alias=quot;Contextquot;)] public class Context { for free
  • 20. Con guring RubyAMF ClassMappings.assume_types = false class Context < ActiveRecord::Base matches [RemoteClass(alias=quot;Contextquot;)] public class Context { with registration ClassMappings.register( :actionscript => 'Context', :ruby => 'Context', :type => 'active_record', :attributes => [quot;idquot;, ...])
  • 21. Con guring RubyAMF ParameterMappings.scaffolding = false def save becomes save(context); @context = params[0] ParameterMappings.scaffolding = true def save save( @context = becomes {context:context} params[:context] );
  • 22. Connecting to Rails via RubyAMF <mx:RemoteObject id=quot;contextsServicequot; destination=quot;rubyamfquot; endpoint=quot;http://localhost:3000/rubyamf_gateway/quot; source=quot;ContextsControllerquot; showBusyCursor=quot;truequot; /> public function save(context:Context):void { var call:AsyncToken = contextsService.save({context:context}); call.addResponder(responder); }
  • 24. 1. Generate and Migrate $ script/generate rubyamf_scaffold context label:string 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 end end $ rake db:migrate
  • 25. 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(quot;nquot;)) end end end end
  • 26. 2. Sample Data work: id: 1 label: Work home: id: 2 label: Home anarco_syndicalist_commune_biweekly_meetings: id: 3 label: Anarcho-syndicalist Commune Bi-weekly Meetings
  • 27. 3. Test class Context < ActiveRecord::Base validates_presence_of :label 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
  • 28. 4. Con gure ClassMappings.register( :actionscript => 'Context', :ruby => 'Context', :type => 'active_record', #:associations => [quot;tasksquot;], :attributes => [quot;idquot;, quot;labelquot;, quot;created_atquot;, quot;updated_atquot;])
  • 29. 5. Wire <mx:RemoteObject id=quot;contextsServicequot; destination=quot;rubyamfquot; endpoint=quot;http://localhost:3000/rubyamf_gateway/quot; source=quot;ContextsControllerquot; showBusyCursor=quot;truequot; /> <mx:RemoteObject id=quot;tasksServicequot; destination=quot;rubyamfquot; endpoint=quot;http://localhost:3000/rubyamf_gateway/quot; source=quot;TasksControllerquot; showBusyCursor=quot;truequot; />
  • 30. 5. Wire public 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); }
  • 31. 5. Wire public 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; ... }
  • 32. X. Rinse and Repeat
  • 34. Gem Plugin + Gem C Extension
  • 35. Gem Plugin C Extension
  • 36.
  • 39. Your Bob Father You Thanks! Tony Hillerson http://slideshare.com/thillerson http://github.com/thillerson http://thillerson.blogspot.com http://effectiveui.com Twitter: thillerson Brightkite: thillerson 39