Sortable_element with RJS does not working

Posted by jaycode on Stack Overflow See other posts from Stack Overflow or by jaycode
Published on 2010-04-10T01:57:12Z Indexed on 2010/04/10 2:03 UTC
Read the original article Hit count: 451

I have a list of images where user can arrange their orders.

When user uploaded an image, I want the list to still be sortable.

I am using a similar upload that was described here: http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/

Please help.

Here are the code for upload in view file:

  <% 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 %>

And in controller view:

  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

Or, to rephrase the question:

Running this:

  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)

Will NOT adding sortable list feature.

Please help,

Thank you

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rjs