ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2008年12月8日 星期一
upload multi file
#Controller:
def uploading
files = []
for i in 1..session[:files].to_i
next if params[:gallery]["file_#{i}".to_sym].to_s.blank?
files << Gallery.create(:file => params[:gallery]["file_#{i}".to_sym]).id.to_s
end
redirect_to :action => "images", :files => files.join("_")
end
def new_upload_field
session[:files]+=1
render :update do |page|
page.insert_html :after, "file_fields", file_column_field("gallery", "file_#{session[:files]}") + "
"
end
end
#View:
<%= javascript_include_tag :defaults %>
<% form_for(Gallery.new, :url => {:action => "uploading"}, :html => {:multipart => true}) do |f| -%>
<%= file_column_field("gallery", "file_#{session[:files]}")%><%= link_to_remote("Add new", :url => {:action => "new_upload_field"}) %>
<%= f.submit("Upload") %>
<% end %>
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言