Sortable lists, database update

Hi,

I have some images and I want to be able to drag them into the order I
want and have the database updated accordingly. I have an unordered
list elsewhere in the application that works well, but for the images
I cant get it working.

In my controller I have:

def updateorder
params[:images].each_with_index { |id,idx| ProductImage.update(id,
:display_order => idx) }
render :text => ‘Updated sort order’
end

Then my view has:

<% @images.each do |image| %> <% if image.product_id == @product.id then %><% end %> <% end %>

Wait for the list to flash yellow before moving another item.

<%= sortable_element ‘images’,
:tag => ‘img’,
:overlap => ‘horizontal’,
:constraint => false,
:update => ‘image-info’,
:complete => visual_effect(:highlight, ‘images’),
:url => { :controller => ‘product_images’, :action =>
“updateorder” } %>

This produces the following HTML:

Wait for the list to flash yellow before moving another item.

The update gives me no errors but there are no changes made to the
database. I have no idea why this isn’t working. Any help would be
great.

Cheers,
Jamie

OkK so after a little more investigation I have narrowed it down to
the update command not working.

I removed the code from the updateorder controller and replaced it
with the line:

render :text => ProductImage.update(‘1’, :display_order => ‘0’)

I get a # character returned but after checking the database nothing
has changed. Using the same code in another controller (with the model
changed) it works fine.

So the only difference I can figure is that ProductImage belongs to
Products, would this difference in the model cause problems with
updating?

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs