Drag and drop sortable list woes


#1

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”}


#2

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)