Forum: Ruby on Rails Drag and drop sortable list woes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rob B. (Guest)
on 2006-06-05 16:50
Well I have it dragging and dropping but its not saving!

 def sort
    @prices = Price.find(params[:id])
    @prices.each do |@price|
      @price.position = params['price'].index(@price.id.to_s) + 1
      @price.save
    end
  render :nothing => true
  end

Current error in the view after dropping is -

undefined method `each' for #<Price:0xb74ec4ac>

/app/controllers/admin_controller.rb:171:in `sort'

Request
Parameters: {"price"=>["2", "3", "1"], "id"=>"3"}
Ioana K. (Guest)
on 2006-06-06 00:43
(Received via mailing list)
Price.find(params[:id]) doesn;t return an array, it's just an Price
object.
Maybe u want smth like:
         @price = Price.find(params[:id]).position
         @price.update_attribute(:position, params['price'].index(@
price.id.to_s) + 1)
This topic is locked and can not be replied to.