我有一个图像列表,用户可以在其中安排他们的订单。
当用户上传图片时,我希望列表仍然是可排序的。
我正在使用此处描述的类似上传:http: //kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/
请帮忙。
以下是在视图文件中上传的代码:
<% form_for [:admin, @new_image], :html => { :target => 'upload_frame', :multipart => true } do |f| %>
<%= hidden_field_tag :update, 'product_images'%>
<%= f.hidden_field :image_owner_id %>
<%= f.hidden_field :image_owner_type %>
<%= f.file_field :image_file %><br />
or get image from this URL: <%= f.text_field :image_file_url %>
<%= f.hidden_field :image_file_temp %><br />
<%= f.submit "Upload Image" %>
<% end %>
在控制器视图中:
def create
@image = Image.new(params[:image])
logger.debug "params are #{params.inspect}"
if @image.save
logger.debug "initiating javascript now"
responds_to_parent do
render :update do |page|
logger.debug "javascript test #{sortable_element("product_images", :url => sort_admin_images_path, :handle => "handle", :constraint => false)}"
page << "show_notification('Image Uploaded');"
page.replace_html params[:update], :partial => '/admin/shared/editor/images', :locals => {:object => @image.image_owner, :updated_image => @image}
page << sortable_element("product_images", :url => sort_admin_images_path, :handle => "handle", :constraint => false)
end
end
#render :partial => '/admin/shared/editor/images', :locals => {:object => @image.image_owner, :updated_image => @image}
else
responds_to_parent do
render :update do |page|
page << "show_notification('Image Upload Error');"
end
end
end
end
或者,换个说法:
运行这个:
page.replace_html params[:update], :partial => '/admin/shared/editor/images', :locals => {:object => @image.image_owner, :updated_image => @image}
page << sortable_element("product_images", :url => sort_admin_images_path, :handle => "handle", :constraint => false)
不会添加可排序列表功能。
请帮忙,
谢谢