Ruby + flex implement weather forecast

Source: Internet
Author: User
Tags cdata

After studying flex for a while, we found that actionscript3 is as dynamic as Ruby and can build very powerful clients. However, for some text-based systems, it is a bit cool-killing, however, in the future, the client is moving towards multi-media, because this will bring a higher user experience. I feel that flex has a good performance on the client, while Ruby is very clever in background business processing. As the two continue to mature and develop, there is reason to believe that the combination of the two will certainly open up a new world in enterprise-level air applications.

The following is an example of using Flex to subscribe to weather forecasts using Ruby on Rails.

Ruby:

Ruby code
  1. ClassWeatherscontroller <applicationcontroller
  2. Require 'rss/123'
  3. Require 'rss/123'
  4. Require 'open-Uri'
  5. DefShow
  6. Feed = "http://www.raychou.com/weather/rss.php? Id = # {Params [: Code]}"
  7. Content = ""
  8. Open (feed)Do| S |
  9. Content = S. Read
  10. End
  11. @ RSS= RSS: parser. parse (content,False)
  12. Render: xml =>@ RSS. Channel <span style = "color: # ff0000" ># directly send without parsing </span>
  13. End
  14. End
Class weatherscontroller <applicationcontroller require 'rss/100' require 'rss/100' require 'open-url' def show feed = "http://www.raychou.com/weather/rss.php? Id = # {Params [: Code]} "content =" "open (feed) Do | S | content = S. read end @ RSS = RSS: parser. parse (content, false) render: xml => @ RSS. channel # directly send endend without Parsing

 

Flex end:

Java code
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" width = "624" Height = "426">
  3. <Mx: SCRIPT>
  4. <! [CDATA [
  5. ImportMX. Events. closeevent;
  6. ImportMX. rpc. Events. resultevent;
  7. [Bindable]
  8. PrivateVaR cityname: array = [{label: "Beijing", data: "54511 "},
  9. {Label: "Nanjing", data: "58238 "},
  10. {Label: "Shanghai", data: "58367 "}
  11. ];
  12. [Bindable]
  13. PrivateVaR selecteditem: object;
  14. <Span style = "color: # ff0000"> // <span> process requests </span>. <span> no result data needs to be parsed, use it directly </span>
  15. PrivateFunction resultweather (Event: resultevent ):Void{
  16. Item1.text = event. Result. Channel. item [0]. Title. tostring ();
  17. Item2.text = event. Result. Channel. item [1]. Title. tostring ();
  18. Item3.text = event. Result. Channel. item [2]. Title. tostring ();
  19. }
  20. ]>
  21. </MX: SCRIPT>
  22. <! -- Send an HTTP request to the backend -->
  23. <Mx: httpservice result = "resultweather (event);" id = "getweather" url = "http: // localhost: 3000/weathers/Show" useproxy = "false">
  24. <Mx: Request>
  25. <Code >{ selecteditem. Data} </code>
  26. </MX: Request>
  27. </MX: httpservice>
  28. <Mx: panel x = "171" Y = "54" width = "418" Height = "333" layout = "absolute" Title = "Weather Forecast query" fontweight = "bold" fontsize =" 13 ">
  29. <Mx: ComboBox x = "120" Y = "28" id = "cmbcityname" dataprovider = "{cityname}" Close = "selecteditem#combobox(event.tar get). selecteditem;
  30. Getweather. Send (); "width =" 164 "fontsize =" 12 "/>
  31. <Mx: label x = "10" Y = "81" id = "Item1" text = "" width = "367" fontsize = "14" color = "#0a6464"/>
  32. <Mx: label x = "10" Y = "126" id = "item2" text = "" width = "367" fontsize = "14" color = "#0a6464"/>
  33. <Mx: Label x = "10" Y = "171" id = "item3" width = "367" fontsize = "14" color = "#0a6464"/>
  34. <Mx: Label x = "37" Y = "30" text = "select city"/>
  35. </MX: Panel>
  36. </MX: Application>
<? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" width = "624" Height = "426"> <mx: SCRIPT> <! [CDATA [import MX. events. closeevent; import MX. RPC. events. resultevent; [Bindable] private var cityname: array = [{label: "Beijing", data: "54511" },{ label: "Nanjing", data: "58238 "}, {label: "Shanghai", data: "58367"}]; [Bindable] private var selecteditem: object; // process the request without parsing the result data, you can directly use the private function resultweather (Event: resultevent): void {item1.text = event. result. channel. item [0]. title. tostring (); item2.text = even T. result. channel. item [1]. title. tostring (); item3.text = event. result. channel. item [2]. title. tostring () ;}]]> </MX: SCRIPT> <! -- Send an HTTP request to the backend --> <mx: httpservice result = "resultweather (event);" id = "getweather" url = "http: // localhost: 3000/weathers/Show "useproxy =" false "> <mx: Request> <code> {selecteditem. data} </code> </MX: Request> </MX: httpservice> <mx: panel x = "171" Y = "54" width = "418" Height = "333" layout = "absolute" Title = "Weather Forecast query" fontweight = "bold" fontsize =" 13 "> <mx: comboBox x = "120" Y = "28" id = "cmbcityname" dataprovider = "{cityname}" Close = "selecteditem#combobox(event.tar get ). selecteditem; getweather. send (); "width =" 164 "fontsize =" 12 "/> <mx: label x = "10" Y = "81" id = "Item1" text = "" width = "367" fontsize = "14" color = "#0a6464"/> <MX: label x = "10" Y = "126" id = "item2" text = "" width = "367" fontsize = "14" color = "#0a6464"/> <MX: label x = "10" Y = "171" id = "item3" width = "367" fontsize = "14" color = "#0a6464"/> <mx: label x = "37" Y = "30" text = "select city"/> </MX: Panel> </MX: Application>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.