이 글은 작업 중에 있는 글입니다.
차후에 설명을 붙이도록 하고 우선 소스만 올려둡니다.
차후에 설명을 붙이도록 하고 우선 소스만 올려둡니다.
Internal Action Script 가 포함된 Flex mxml 파일
<?xml version="1.0"?>
<!-- 게시판 -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="svcPosts.send();"
>
<mx:HTTPService id="svcPosts" url="http://localhost:3000/posts.xml" method = "GET" resultFormat="e4x" result="postsResultHandler(event)" fault="postsFaultHandler(event)">
<mx:request>
<limit>20</limit>
</mx:request>
</mx:HTTPService>
<mx:HTTPService contentType="application/xml"
id="svcCreatePost"
url="http://localhost:3000/posts"
useProxy="false" method="POST">
<mx:request xmlns="">
<post>
<name>{tAuthor.text}</name>
<subject>{tSubject.text}</subject>
<body>{tBody.text}</body>
</post>
</mx:request>
</mx:HTTPService>
<mx:HTTPService id="svcDeletePost"
result="svcPosts.send();"
url="http://localhost:3000/posts"
method="POST"
useProxy="false"/>
<mx:HTTPService id="svcEditPost"
result="svcPosts.send();"
url="http://localhost:3000/posts"
method="POST"
useProxy="false">
<mx:request xmlns="">
<post>
<name>{oldAuthor.text}</name>
<subject>{oldSubject.text}</subject>
<body>{oldBody.text}</body>
</post>
</mx:request>
</mx:HTTPService>
<mx:Style>
Panel { font-size: 12pt }
</mx:Style>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert
import mx.events.CloseEvent;
[Bindable]
private var posts:XML;
public function postsResultHandler(event:ResultEvent):void
{
posts = event.result as XML
//Alert.show(posts);
}
public function postsFaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.message, "Could not load posts!");
}
private function deleteHandler(event:Event) : void
{
Alert.show("정말 이 항목을 삭제하시겠습니까?", "포스트 삭제", 3, this,
function(event:CloseEvent):void
{
if (event.detail==Alert.YES)
svcDeletePost.url = 'http://localhost:3000/posts/'+dgPosts.selectedItem.id+'.xml';
svcDeletePost.send({id: dgPosts.selectedItem.id, _method:'DELETE'});
});
}
]]>
</mx:Script>
<mx:Panel title="Flexible Board" height="100%" width="100%"
paddingTop="10" paddingLeft="10" paddingRight="10">
<mx:Label width="100%" color="black"
text="게시판입니다."/>
<mx:DataGrid id="dgPosts" width="100%" height="100%" rowCount="20" dataProvider="{posts.post}">
<mx:columns>
<mx:DataGridColumn dataField="id" headerText="No" width="40" textAlign="center" />
<mx:DataGridColumn dataField="name" headerText="이름" width="100" textAlign="center" />
<mx:DataGridColumn dataField="subject" headerText="제목"/>
<mx:DataGridColumn dataField="created_at" headerText="글 쓴 날짜" width="150" textAlign="center" />
<mx:DataGridColumn dataField="updated_at" headerText="변경된 날짜" width="150" textAlign="center"/>
</mx:columns>
</mx:DataGrid>
<mx:Form width="100%" height="100%">
<mx:FormItem label="이름">
<mx:TextInput text="{dgPosts.selectedItem.name}" id="oldAuthor" />
</mx:FormItem>
<mx:FormItem label="제목">
<mx:TextInput text="{dgPosts.selectedItem.subject}" id="oldSubject" />
</mx:FormItem>
<mx:FormItem label="글 쓴 날짜">
<mx:Label text="{dgPosts.selectedItem.created_at}"/>
</mx:FormItem>
<mx:FormItem label="변경된 날짜">
<mx:Label text="{dgPosts.selectedItem.updated_at}"/>
</mx:FormItem>
<mx:FormItem label="내용">
<mx:TextArea width="400" height="100" text="{dgPosts.selectedItem.body}" id="oldBody" />
</mx:FormItem>
<mx:Button label="글 수정"
click="svcEditPost.url='http://localhost:3000/posts/'+dgPosts.selectedItem.id+'.xml';svcEditPost.send({_method:'PUT'});svcPosts.send();"/>
<mx:Button label="글 삭제"
click="deleteHandler(event);"/>
</mx:Form>
<mx:Form width="100%" height="100%">
<mx:FormItem label="이름">
<mx:TextInput id="tAuthor" />
</mx:FormItem>
<mx:FormItem label="제목">
<mx:TextInput id="tSubject" />
</mx:FormItem>
<mx:FormItem label="내용">
<mx:TextArea id="tBody" width="400" height="100"/>
</mx:FormItem>
<mx:Button label="글 등록"
click="svcCreatePost.send();svcPosts.send();"/>
</mx:Form>
<mx:ControlBar horizontalAlign="center">
<mx:Button label="새로 고침" click="svcPosts.send();"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
<!-- 게시판 -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="svcPosts.send();"
>
<mx:HTTPService id="svcPosts" url="http://localhost:3000/posts.xml" method = "GET" resultFormat="e4x" result="postsResultHandler(event)" fault="postsFaultHandler(event)">
<mx:request>
<limit>20</limit>
</mx:request>
</mx:HTTPService>
<mx:HTTPService contentType="application/xml"
id="svcCreatePost"
url="http://localhost:3000/posts"
useProxy="false" method="POST">
<mx:request xmlns="">
<post>
<name>{tAuthor.text}</name>
<subject>{tSubject.text}</subject>
<body>{tBody.text}</body>
</post>
</mx:request>
</mx:HTTPService>
<mx:HTTPService id="svcDeletePost"
result="svcPosts.send();"
url="http://localhost:3000/posts"
method="POST"
useProxy="false"/>
<mx:HTTPService id="svcEditPost"
result="svcPosts.send();"
url="http://localhost:3000/posts"
method="POST"
useProxy="false">
<mx:request xmlns="">
<post>
<name>{oldAuthor.text}</name>
<subject>{oldSubject.text}</subject>
<body>{oldBody.text}</body>
</post>
</mx:request>
</mx:HTTPService>
<mx:Style>
Panel { font-size: 12pt }
</mx:Style>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert
import mx.events.CloseEvent;
[Bindable]
private var posts:XML;
public function postsResultHandler(event:ResultEvent):void
{
posts = event.result as XML
//Alert.show(posts);
}
public function postsFaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.message, "Could not load posts!");
}
private function deleteHandler(event:Event) : void
{
Alert.show("정말 이 항목을 삭제하시겠습니까?", "포스트 삭제", 3, this,
function(event:CloseEvent):void
{
if (event.detail==Alert.YES)
svcDeletePost.url = 'http://localhost:3000/posts/'+dgPosts.selectedItem.id+'.xml';
svcDeletePost.send({id: dgPosts.selectedItem.id, _method:'DELETE'});
});
}
]]>
</mx:Script>
<mx:Panel title="Flexible Board" height="100%" width="100%"
paddingTop="10" paddingLeft="10" paddingRight="10">
<mx:Label width="100%" color="black"
text="게시판입니다."/>
<mx:DataGrid id="dgPosts" width="100%" height="100%" rowCount="20" dataProvider="{posts.post}">
<mx:columns>
<mx:DataGridColumn dataField="id" headerText="No" width="40" textAlign="center" />
<mx:DataGridColumn dataField="name" headerText="이름" width="100" textAlign="center" />
<mx:DataGridColumn dataField="subject" headerText="제목"/>
<mx:DataGridColumn dataField="created_at" headerText="글 쓴 날짜" width="150" textAlign="center" />
<mx:DataGridColumn dataField="updated_at" headerText="변경된 날짜" width="150" textAlign="center"/>
</mx:columns>
</mx:DataGrid>
<mx:Form width="100%" height="100%">
<mx:FormItem label="이름">
<mx:TextInput text="{dgPosts.selectedItem.name}" id="oldAuthor" />
</mx:FormItem>
<mx:FormItem label="제목">
<mx:TextInput text="{dgPosts.selectedItem.subject}" id="oldSubject" />
</mx:FormItem>
<mx:FormItem label="글 쓴 날짜">
<mx:Label text="{dgPosts.selectedItem.created_at}"/>
</mx:FormItem>
<mx:FormItem label="변경된 날짜">
<mx:Label text="{dgPosts.selectedItem.updated_at}"/>
</mx:FormItem>
<mx:FormItem label="내용">
<mx:TextArea width="400" height="100" text="{dgPosts.selectedItem.body}" id="oldBody" />
</mx:FormItem>
<mx:Button label="글 수정"
click="svcEditPost.url='http://localhost:3000/posts/'+dgPosts.selectedItem.id+'.xml';svcEditPost.send({_method:'PUT'});svcPosts.send();"/>
<mx:Button label="글 삭제"
click="deleteHandler(event);"/>
</mx:Form>
<mx:Form width="100%" height="100%">
<mx:FormItem label="이름">
<mx:TextInput id="tAuthor" />
</mx:FormItem>
<mx:FormItem label="제목">
<mx:TextInput id="tSubject" />
</mx:FormItem>
<mx:FormItem label="내용">
<mx:TextArea id="tBody" width="400" height="100"/>
</mx:FormItem>
<mx:Button label="글 등록"
click="svcCreatePost.send();svcPosts.send();"/>
</mx:Form>
<mx:ControlBar horizontalAlign="center">
<mx:Button label="새로 고침" click="svcPosts.send();"/>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
레일스 어플리케이션의 DB 스키마
create_table "posts", :force => true do |t|
t.string "name"
t.string "subject"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
end
t.string "name"
t.string "subject"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
end
레일스 어플리케이션 컨트롤러(REST)
class PostsController < ApplicationController
# GET /posts
# GET /posts.xml
def index
@posts = Post.find(:all, :order => 'created_at desc')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts.to_xml(:dasherize => false) }
end
end
# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post.to_xml(:dasherize => false) }
end
end
# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post.to_xml(:dasherize => false) }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(@post) }
format.xml { render :xml => @post.to_xml(:dasherize => false), :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity, :dasherize => false }
end
end
end
# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
flash[:notice] = 'Post was successfully updated.'
format.html { redirect_to(@post) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
end
end
# GET /posts
# GET /posts.xml
def index
@posts = Post.find(:all, :order => 'created_at desc')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts.to_xml(:dasherize => false) }
end
end
# GET /posts/1
# GET /posts/1.xml
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post.to_xml(:dasherize => false) }
end
end
# GET /posts/new
# GET /posts/new.xml
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post.to_xml(:dasherize => false) }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.xml
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to(@post) }
format.xml { render :xml => @post.to_xml(:dasherize => false), :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity, :dasherize => false }
end
end
end
# PUT /posts/1
# PUT /posts/1.xml
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
flash[:notice] = 'Post was successfully updated.'
format.html { redirect_to(@post) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.xml
def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
end
end
생성된 SWF
글 검색 결과 - Ruby on Rails (총 3개)
이올린에 북마크하기

이올린에 추천하기



