Rails Recipes: Drag''n''Drop Sortable List with unique index?

Joshua Muheim
Sun, 10 Dec 2006 22:37:55 -0000

Hi all

On page 31 of the "Pragmatic Programmer''s Rails Recipes" book
there''s
the recipe "Creating a Drag-and-Drop Sortable List". I think this is
very useful, but sadly I have a unique constraint on my product_id and
position fields (because the acts_as_list scope is product_id).
When I try the recipe then Rails crashes very very badly: I have to
restart the server *on a new port* because the previously used port
seems to be locked or something like that (I''m using Locomotive)... No
idea.

So can anybody please help me rewriting the sort action so it is capable
to sort the stuff with a unique index on the fields product_id and
position? Thank you very much, I''m still no great Ruby programmer
yet...
:-)

  def sort
    produkt = Produkt.find(params[:id])
    produkt.bilder.each do |bild|
      bild.position =
params[''bilder_list''].index(bild.id.to_s) + 1
      bild.save
    end
    render :nothing => true
  end

Keep care,
Josh

--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---