0

我有一个图像列表,用户可以在其中安排他们的订单。

当用户上传图片时,我希望列表仍然是可排序的。

我正在使用此处描述的类似上传: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)

不会添加可排序列表功能。

请帮忙,

谢谢

4

2 回答 2

0

我认为问题很可能是在页面首次加载时创建了可排序的。我遇到过这个问题几次。向列表中添加新元素意味着您必须再次调用 sortable 函数才能将新元素包含在排序中。

我不是原型/脚本,但可能有一种方法可以让可排序元素监听将元素添加到列表的事件。jQuery 有一组重新绑定事件,它们将响应添加到 DOM 的新元素,可能在其他库中类似。

于 2010-04-11T01:18:26.637 回答
0

找到了!

代替:

  page.replace_html params[:update], :partial => '/admin/shared/editor/images', :locals => {:object => @image.image_owner, :updated_image => @image}

利用

  page.replace params[:update], :partial => '/admin/shared/editor/images', :locals => {:object => @image.image_owner, :updated_image => @image}
于 2010-04-13T16:41:08.690 回答