0

I'm following Railcasts #147 using Rails 4 instead of 3.

The method below is not passing in Rails 4. So far all, all is working except for updating the databse with the new sorted position. Any idea how I can mass update the records?

def sort
  params[:faq].each_with_index do |id, index|
  Faq.update_all({position: index+1}, {id: id})
end
  render nothing: true
end

Much appreciated.

0

2 Answers 2

1

In case anyone is wondering, this is what worked for me in Rails 4:

 def sort
  params[:video].each_with_index do |id, index|
   Video.update(id, position: index+1)
  end
  render :queue
 end
0

In latest rails versions, this is deprecated

Faq.update_all({position: index+1}, {id: id})

Try

Faq.update_all(position: index+1, id: id)