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
On 28/06/06, Jamie D <jam5t3r.lists@gmail.com>
wrote:> 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:
>
> <div id="images" style="border: solid black 1px; width:
672px;">
> <% @images.each do |image| %>
> <% if image.product_id == @product.id then %><img
> src="/images/store/<%= image.filename %>"
id="image_<%= image.id %>"
> /><% end %>
> <% end %>
> </div>
>
> <p id="image-info" class="notice">Wait for the
list to flash yellow
> before moving another item.</p>
>
> <%= 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:
>
> <div id="images" style="border: solid black 1px; width:
672px;">
> <img src="/images/store/t-shirt01.jpg"
id="image_12" />
> <img src="/images/store/t-shirt02.jpg"
id="image_13" />
> <img src="/images/store/t-shirt03.jpg"
id="image_23" />
> </div>
>
> <p id="image-info" class="notice">Wait for the
list to flash yellow
> before moving another item.</p>
>
> <script type="text/javascript">
> //<![CDATA[
> Sortable.create("images", {constraint:false,
onUpdate:function(){new
> Ajax.Updater(''image-info'',
''/admin2/product_images/updateorder'',
> {asynchronous:true, evalScripts:true, onComplete:function(request){new
> Effect.Highlight("images",{});},
> parameters:Sortable.serialize("images")})},
overlap:''horizontal'',
> tag:''img''})
> //]]>
> </script>
>
> 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
>