Flex and Rails   Tony Hillerson
                  Software Architect

with RubyAMF      EffectiveUI
                  Rail...
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|
    i...
JSON

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


        http://as3corlib.googlecode.com


   var o...
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/controlle...
Con guring RubyAMF
module RubyAMF
  module Configuration
    ClassMappings.translate_case = true
    ClassMappings.assume_...
Con guring RubyAMF
ClassMappings.translate_case = false

public var created_at:Date;


ClassMappings.translate_case = true...
Con guring RubyAMF
  ClassMappings.assume_types = true

  class Context < ActiveRecord::Base
              matches
   [Rem...
Con guring RubyAMF
  ClassMappings.assume_types = false

  class Context < ActiveRecord::Base
              matches
   [Re...
Con guring RubyAMF
              ParameterMappings.scaffolding = false

                                       def save
  ...
Connecting to Rails via
       RubyAMF
<mx:RemoteObject
    	id=quot;contextsServicequot;
    	destination=quot;rubyamfquo...
Development Work ow
1. Generate and Migrate
$ script/generate rubyamf_scaffold context label:string
class CreateContexts < ActiveRecord::Migra...
def load_all
  @contexts = Context.find :all

  respond_to do |format|
    format.amf { render :amf => @contexts }
  end
e...
2. Sample Data
work:
  id: 1
  label: Work

home:
  id: 2
  label: Home

anarco_syndicalist_commune_biweekly_meetings:
  i...
3. Test
class Context < ActiveRecord::Base
  validates_presence_of :label



class ContextTest < ActiveSupport::TestCase
 ...
4. Con gure

ClassMappings.register(
  :actionscript => 'Context',
  :ruby          => 'Context',
  :type          => 'act...
5. Wire
<mx:RemoteObject
    	id=quot;contextsServicequot;
    	destination=quot;rubyamfquot;
    	endpoint=quot;http://lo...
5. Wire
public function loadAll():void {
	 var call:AsyncToken = service.load_all();
	 call.addResponder(responder);
}

pu...
5. Wire
public function execute(event:CairngormEvent):void {
	 var evt:SaveContextEvent = event as SaveContextEvent;
	 var...
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




                                ...
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
Upcoming SlideShare
Loading in...5
×

Integrating Flex And Rails With Ruby Amf

4,862

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,862
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
86
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Integrating Flex And Rails With Ruby Amf

  1. 1. Flex and Rails Tony Hillerson Software Architect with RubyAMF EffectiveUI RailsConf
  2. 2. Code and Slides: http://github.com/thillerson/preso_code/
  3. 3. Sample du Jour: Stuff
  4. 4. Why Flex and Rails? They Make The Great Tag Team!
  5. 5. [SKIP INTRO]
  6. 6. What are the Options?
  7. 7. XML
  8. 8. XML is the Default Option
  9. 9. # 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
  10. 10. JSON Javascript Object Notation
  11. 11. JSON is in Rails Too format.json { render :json => @context.to_json } http://as3corlib.googlecode.com var obj:Object = JSON.decode(jsonString)
  12. 12. AMF Action Message Format
  13. 13. AMF is the Good Stuff Buck Thinks it’s Great!
  14. 14. RubyAMF http://rubyamf.org http://rubyamf.googlecode.com
  15. 15. 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
  16. 16. 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
  17. 17. Con guring RubyAMF ClassMappings.translate_case = false public var created_at:Date; ClassMappings.translate_case = true public var createdAt:Date; // created_at in rails
  18. 18. Con guring RubyAMF ClassMappings.assume_types = true class Context < ActiveRecord::Base matches [RemoteClass(alias=quot;Contextquot;)] public class Context { for free
  19. 19. 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;, ...])
  20. 20. 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] );
  21. 21. 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); }
  22. 22. Development Work ow
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 27. 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;])
  28. 28. 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; />
  29. 29. 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); }
  30. 30. 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; ... }
  31. 31. X. Rinse and Repeat
  32. 32. The Future
  33. 33. Gem Plugin + Gem C Extension
  34. 34. Gem Plugin C Extension
  35. 35. An Impassioned Plea
  36. 36. Resources: http://rubyamf.googlecode.com http://groups.google.com/group/rubyamf http://github.com/thillerson/rubyamf
  37. 37. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×