SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
Daniel Wanja
Tony Hillerson
We wrote a
                     book!

• Yea, us!
• What the heck?
Why Flex on Rails?

• You already know “why Rails?”
• Flex is another tool in the toolbox
• Service oriented
Agenda

• A bit about Flex
• Highlights and source from the book
• Drinking
Flex is...


• Part of Adobe’s Flash platform
• Open Source (framework) and free
Flex is...

• A compiler
• An XML language - MXML
• A set of components
Flex ...

• A way to write ActionScript declaratively
• Compiles to ActionScript
• ActionScript -> SWF
• Runs in the Flash Player
Flex on Rails
 • Compiled source - keep
   separate
 • SWF -> /public during
   deployment
 • Flex talks to Rails with
   XML, JSON, or AMF
Development
        Workflow
• Open SWF or HTML Wrapper from Public
• HTML Wrapper - can use relative urls
• SWF - Hardcode localhost:3000 :-(
• Either - Load an url from config :-)
Codes!
    git@github.com:danielwanja/flexonrails.git
•   Passing Data with XML
•   RESTful Services
•   Passing Data with AMF
•   Data Visualization
•   Building Flex with Rake
•   Read the Source!
•   Observers in Flex
•   Authentication
•   Hierarchical Data With AMF
•   Advanced Data Grid with Awesome Nested Set
•   Server Push with Juggernaut
•   Flex and Javascript
•   File Upload
Passing Data with XML
 Rails        Person.new(:first_name => 'daniel', :last_name =>
              'wanja').to_xml


          var person:XML = <person>
 Flex     <first_name>tony</first_name>
          <last_name>hillerson</last_name></person>


Getting   <mx:HTTPService id=quot;indexquot;
            url=quot;http://localhost:3000/people.xmlquot;
XML to      resultFormat=quot;e4xquot; />

 Flex     index.send()

          <mx:HTTPService id=quot;updatequot;
            url=quot;http://localhost:3000/people/{id}.xml?_method=putquot;
Sending     contentType=quot;application/xmlquot;
            resultFormat=quot;e4xquot;
XML to      method=quot;POSTquot;

 Rails      result=quot;index.send()quot; />



                                                                      02
          update.send(person)
RESTful Services
HTTP verb                   URL                                 Controller



GET         /accounts/:account_id/positions       {:action=>quot;indexquot;,
                                                  :controller=>quot;positionsquot;}


POST        /accounts/:account_id/positions       {:action=>quot;createquot;,
                                                  :controller=>quot;positionsquot;}


GET         /accounts/:account_id/positions/:id   {:action=>quot;showquot;,
                                                  :controller=>quot;positionsquot;}


PUT         /accounts/:account_id/positions/:id   {:action=>quot;updatequot;,
                                                  :controller=>quot;positionsquot;}


DELETE      /accounts/:account_id/positions/:id   {:action=>quot;destroyquot;,
                                                  :controller=>quot;positionsquot;}




                                                                              03
Nested Resources
class Account < ActiveRecord::Base   class Position < ActiveRecord::Base class Movement < ActiveRecord::Base
  has_many :positions,                 belongs_to :account                 belongs_to :position
           :dependent => :destroy      has_many :movements,              end
end                                             :dependent => :destroy
                                     end




             /accounts/:id

                               /accounts/:account_id/positions/:id                      

                           /accounts/:account_id/positions/:position_id/movements/:id
Data Visualization




                     07
Authentication

• All Flex service calls go through the
  browser
• AIR manages cookies
• = Standard cookie based credentials work
  fine
Hierarchical Data with
        AMF

• Works nicely with Awesome Nested Set
• Good for retrieving Object Graphs
• More work when sending Object Graphs
Read the Source!


• Flex source is available in Flex Builder
• MXML is compiled to ActionScript
Observers in Flex

• Binding is sweet
• {} notation
• BindingUtils
• ChangeWatcher
Building Flex with Rake


• Simple shell command to mxmlc
• mxmlc needs to be in the path
Flex and Javascript

• HTML *and* Flex is sometimes the right
  answer
• Flex Ajax Bridge
• ExternalInterface
Advanced Data Grid with
              Awesome Nested Set
class Category < ActiveRecord::Base
  acts_as_nested_set
  def full_xml(builder=nil)
    xml = builder ||= Builder::XmlMarkup.new(:indent => 2)
    xml.category(:id => id,
                 :name => name,
                 :description => description,
                 :qty_in_stock => qty_in_stock) do
      children.each { |child| child.full_xml(xml) }
    end
  end
end




 <mx:HTTPService id=quot;categoriesquot; url=quot;http://localhost:3000/categoriesquot; resultFormat=quot;e4xquot; />




                                                                                            18
Server Push with Juggernaut

     message to socket




                                                                                 localhost:3000/
                                                            1. post to http://
      3. push JSON




                                     Nt




                                                                                    messenger/
                                   O cke




                                                                                      message
                                 JS so
                               h
                             us e to
                           p
                         3. sag
                           es
                         m




                           2. send_to_channels
       Juggernaut
                                                 Rails Application
       Push Server




                                                                                                   20
Server Push with Juggernaut
                                                                                         class MessengerController <
                                                                                         ApplicationController
                                                                                           def message
                                                                                             data = {:user => params[:user], :message =>
                                                                                         params[:message]}
             message to socket




                                                                    localhost:3000/
                                                                    1. post to http://
              3. push JSON




                                            Nt




                                                                       messenger/
                                           O ke




                                                                         message
                                         JS soc
                                       h
                                     us to
                                  . p age
                                                                                         Juggernaut.send_to_channel(data, :im_channel)
                                 3s
                                   es
                                 m

                                                                                             render :nothing => true
                                                                                           end
                                   2. send_to_channels
                                                                                         end
               Juggernaut
                                                         Rails Application
               Push Server




<mx:HTTPService id=quot;sendMessagequot; url=quot;http://
                                                                                         <net:XMLSocket id=quot;socketquot;
localhost:3000/messenger/messagequot;
                                                                                               connect=quot;connectHandler(event)quot;
        method=quot;POSTquot; result=quot;msg.text=''quot;
                                                                                               data=quot;dataHandler(event)quot;
fault=quot;mx.controls.Alert.show(event.fault.faultS
                                                                                               close=quot;closeHandler(event)quot;
tring);quot;>
                                                                                               ioError=quot;ioErrorHandler(event)quot;
  <mx:request xmlns=quot;quot;>
    <user>{user.text}</user>
                                                                                         securityError=quot;securityErrorHandler(event)quot; />
    <message>{msg.text}</message>
  </mx:request>
                                                                                         socket.connect(hostName, port);
</mx:HTTPService>
File Upload
                                                 class Asset < ActiveRecord::Base
<net:FileReference id=quot;fileReferencequot;              has_attachment :storage => :file_system
    select=quot;selectHandler(event)quot; />             end

private function selectHandler(event:Event):void class AssetsController < ApplicationController
{                                                   def create
  var request:URLRequest =                              @asset = Asset.new(params[:asset])
  new URLRequest(quot;http://localhost:3000/assetsquot;)        if @asset.save
  var uploadDataFieldName:String =                        render(:nothing => true, :status => 200)
                           'asset[uploaded_data]'       else
  fileReference.upload(request,                           render(:nothing => true, :status => 500)
                            uploadDataFieldName);       end
}                                                   end
                                                  end




                                                                                               22

Más contenido relacionado

Último

+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@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

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?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+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...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
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...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 

Destacado

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Flexonrails Derailed Talk

  • 2. We wrote a book! • Yea, us! • What the heck?
  • 3. Why Flex on Rails? • You already know “why Rails?” • Flex is another tool in the toolbox • Service oriented
  • 4. Agenda • A bit about Flex • Highlights and source from the book • Drinking
  • 5. Flex is... • Part of Adobe’s Flash platform • Open Source (framework) and free
  • 6. Flex is... • A compiler • An XML language - MXML • A set of components
  • 7. Flex ... • A way to write ActionScript declaratively • Compiles to ActionScript • ActionScript -> SWF • Runs in the Flash Player
  • 8. Flex on Rails • Compiled source - keep separate • SWF -> /public during deployment • Flex talks to Rails with XML, JSON, or AMF
  • 9. Development Workflow • Open SWF or HTML Wrapper from Public • HTML Wrapper - can use relative urls • SWF - Hardcode localhost:3000 :-( • Either - Load an url from config :-)
  • 10. Codes! git@github.com:danielwanja/flexonrails.git • Passing Data with XML • RESTful Services • Passing Data with AMF • Data Visualization • Building Flex with Rake • Read the Source! • Observers in Flex • Authentication • Hierarchical Data With AMF • Advanced Data Grid with Awesome Nested Set • Server Push with Juggernaut • Flex and Javascript • File Upload
  • 11. Passing Data with XML Rails Person.new(:first_name => 'daniel', :last_name => 'wanja').to_xml var person:XML = <person> Flex <first_name>tony</first_name> <last_name>hillerson</last_name></person> Getting <mx:HTTPService id=quot;indexquot; url=quot;http://localhost:3000/people.xmlquot; XML to resultFormat=quot;e4xquot; /> Flex index.send() <mx:HTTPService id=quot;updatequot; url=quot;http://localhost:3000/people/{id}.xml?_method=putquot; Sending contentType=quot;application/xmlquot; resultFormat=quot;e4xquot; XML to method=quot;POSTquot; Rails result=quot;index.send()quot; /> 02 update.send(person)
  • 12. RESTful Services HTTP verb URL Controller GET /accounts/:account_id/positions {:action=>quot;indexquot;, :controller=>quot;positionsquot;} POST /accounts/:account_id/positions {:action=>quot;createquot;, :controller=>quot;positionsquot;} GET /accounts/:account_id/positions/:id {:action=>quot;showquot;, :controller=>quot;positionsquot;} PUT /accounts/:account_id/positions/:id {:action=>quot;updatequot;, :controller=>quot;positionsquot;} DELETE /accounts/:account_id/positions/:id {:action=>quot;destroyquot;, :controller=>quot;positionsquot;} 03
  • 13. Nested Resources class Account < ActiveRecord::Base class Position < ActiveRecord::Base class Movement < ActiveRecord::Base has_many :positions, belongs_to :account belongs_to :position :dependent => :destroy has_many :movements, end end :dependent => :destroy end /accounts/:id /accounts/:account_id/positions/:id /accounts/:account_id/positions/:position_id/movements/:id
  • 15. Authentication • All Flex service calls go through the browser • AIR manages cookies • = Standard cookie based credentials work fine
  • 16. Hierarchical Data with AMF • Works nicely with Awesome Nested Set • Good for retrieving Object Graphs • More work when sending Object Graphs
  • 17. Read the Source! • Flex source is available in Flex Builder • MXML is compiled to ActionScript
  • 18. Observers in Flex • Binding is sweet • {} notation • BindingUtils • ChangeWatcher
  • 19. Building Flex with Rake • Simple shell command to mxmlc • mxmlc needs to be in the path
  • 20. Flex and Javascript • HTML *and* Flex is sometimes the right answer • Flex Ajax Bridge • ExternalInterface
  • 21. Advanced Data Grid with Awesome Nested Set class Category < ActiveRecord::Base acts_as_nested_set def full_xml(builder=nil) xml = builder ||= Builder::XmlMarkup.new(:indent => 2) xml.category(:id => id, :name => name, :description => description, :qty_in_stock => qty_in_stock) do children.each { |child| child.full_xml(xml) } end end end <mx:HTTPService id=quot;categoriesquot; url=quot;http://localhost:3000/categoriesquot; resultFormat=quot;e4xquot; /> 18
  • 22. Server Push with Juggernaut message to socket localhost:3000/ 1. post to http:// 3. push JSON Nt messenger/ O cke message JS so h us e to p 3. sag es m 2. send_to_channels Juggernaut Rails Application Push Server 20
  • 23. Server Push with Juggernaut class MessengerController < ApplicationController def message data = {:user => params[:user], :message => params[:message]} message to socket localhost:3000/ 1. post to http:// 3. push JSON Nt messenger/ O ke message JS soc h us to . p age Juggernaut.send_to_channel(data, :im_channel) 3s es m render :nothing => true end 2. send_to_channels end Juggernaut Rails Application Push Server <mx:HTTPService id=quot;sendMessagequot; url=quot;http:// <net:XMLSocket id=quot;socketquot; localhost:3000/messenger/messagequot; connect=quot;connectHandler(event)quot; method=quot;POSTquot; result=quot;msg.text=''quot; data=quot;dataHandler(event)quot; fault=quot;mx.controls.Alert.show(event.fault.faultS close=quot;closeHandler(event)quot; tring);quot;> ioError=quot;ioErrorHandler(event)quot; <mx:request xmlns=quot;quot;> <user>{user.text}</user> securityError=quot;securityErrorHandler(event)quot; /> <message>{msg.text}</message> </mx:request> socket.connect(hostName, port); </mx:HTTPService>
  • 24. File Upload class Asset < ActiveRecord::Base <net:FileReference id=quot;fileReferencequot; has_attachment :storage => :file_system select=quot;selectHandler(event)quot; /> end private function selectHandler(event:Event):void class AssetsController < ApplicationController { def create var request:URLRequest = @asset = Asset.new(params[:asset]) new URLRequest(quot;http://localhost:3000/assetsquot;) if @asset.save var uploadDataFieldName:String = render(:nothing => true, :status => 200) 'asset[uploaded_data]' else fileReference.upload(request, render(:nothing => true, :status => 500) uploadDataFieldName); end } end end 22