SlideShare a Scribd company logo
1 of 24
Download to read offline
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

More Related Content

Recently uploaded

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Recently uploaded (20)

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 

Featured

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 2024Neil Kimberley
 
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)contently
 
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 2024Albert Qian
 
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 InsightsKurio // The Social Media Age(ncy)
 
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 2024Search Engine Journal
 
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 summarySpeakerHub
 
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 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 Tessa Mero
 
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 IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
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 managementMindGenius
 
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...RachelPearson36
 
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...Applitools
 
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 WorkGetSmarter
 
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...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (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