Professional Documents
Culture Documents
Software Architect
http://as3corlib.googlecode.com
http://rubyamf.org
http://rubyamf.googlecode.com
Installing RubyAMF
$ script/plugin install http://rubyamf.googlecode.com/svn/current/rubyamf
• config/routes.rb modified:
ActionController::Routing::Routes.draw do |map|
map.rubyamf_gateway 'rubyamf_gateway',
:controller => 'rubyamf', :action => 'gateway'
end
Configuring 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 => ["context"],
:attributes => ["id", "label", "context_id",
"completed_at", "created_at", "updated_at"])
end
end
Configuring RubyAMF
ClassMappings.translate_case = false
ClassMappings.translate_case = true
for free
Configuring RubyAMF
ClassMappings.assume_types = false
with registration
ClassMappings.register(
:actionscript => 'Context',
:ruby => 'Context',
:type => 'active_record',
:attributes => ["id", ...])
Configuring RubyAMF
ParameterMappings.scaffolding = false
def save
save(context); becomes @context = params[0]
ParameterMappings.scaffolding = true
def save
save(
@context =
{context:context} becomes params[:context]
);
Connecting to Rails via
RubyAMF
<mx:RemoteObject
id="contextsService"
destination="rubyamf"
endpoint="http://localhost:3000/rubyamf_gateway/"
source="ContextsController"
showBusyCursor="true"
/>
public function save(context:Context):void {
var call:AsyncToken =
contextsService.save({context:context});
call.addResponder(responder);
}
Development Workflow
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("\n"))
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
ClassMappings.register(
:actionscript => 'Context',
:ruby => 'Context',
:type => 'active_record',
#:associations => ["tasks"],
:attributes => ["id", "label", "created_at", "updated_at"])
5. Wire
<mx:RemoteObject
id="contextsService"
destination="rubyamf"
endpoint="http://localhost:3000/rubyamf_gateway/"
source="ContextsController"
showBusyCursor="true"
/>
<mx:RemoteObject
id="tasksService"
destination="rubyamf"
endpoint="http://localhost:3000/rubyamf_gateway/"
source="TasksController"
showBusyCursor="true"
/>
5. Wire
public function loadAll():void {
var call:AsyncToken = service.load_all();
call.addResponder(responder);
}
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