2
我有具有圖片上傳的一個領域,如導軌形式的回形針文件附件:form_remote_tag上傳
<% form_for @c, :html => { :multipart => true } do |f| %>
<%= f.file_field(:b, :size=>63, :class=>"fontsize13") %>
<%= image_tag @c.b.url(:thumb) %>
<% end %>
在保存這種形式,動作
def update
@c = C.find(params[:id])
if params[:c]
@c.update_attributes(params[:c])
if @c.save
redirect_to :action => "index"
else
flash[:error] = @c.errors.full_messages.join('<br />')
end
end
end
這將上傳圖片並再次加載相同的頁面,以便在預覽和佈局標誌中顯示上傳的圖片。
我想通過ajax而不是頁面刷新再次顯示圖像。
我已經
<% form_remote_tag :url => {:controller => "c",:action => "update"}, :html => {:multipart => true } do |f| -%>
<%= f.file_field :b%>
<% end %>
與form_remote_tag嘗試,但這個說明我的錯誤是Undefined method file_field for nil
請給點建議
http://justinvadakkan.blogspot.com/2010/12/file-upload-without-reload-page.html解決了我的問題 – useranon 2011-05-17 06:12:34