资 源 简 介
Normally, to upload file,we will write some codes in the view page
like:
<% form_for(:photo, :url => {:action => :create}, :html =>
{ :multipart => true}) do |form| -%>
Upload A Image:remote\_form\_for(:photo, :url => {:action => :create}) do |form| -%>
>
Upload A Image:
end -%>
Now, file upload will post via a iframe without refresh the page.
But how about the rjs?
We won"t forget it.
Add some codes in the controller as bellow:
1. iframe request
> if params[:HTTP\_X\_REQUESTED\_WITH] && request.post?
> > render :template => "photos/create.rjs", :layout =>
false, :content\_type => "text/html"
> else
1. normal request
> > respond\_to do |format|
> > > format.html {redirect\_to :action => "new", :id => @photo if
request.post?}
> > > format.js
> > end
> end
Now we can render different views by the request type automatically.