I'm trying to do a for each loop to update my database. I was using this piece of code to make the update:
def update
respond_to do |format|
@t_id = params[:t_id]
@t_order = params[:order]
@t_relation = TRelation.where('t_id' => @t_id)
@i = 0;
@t_order.each do |p|
@t_relation = TRelation.where('t_id = ? and
video_id = ?', @t_id, p[1][@i])
@i = @i + 1
@t_relation[0].t_order = @i
@t_relation[0].save
end
format.json { render :nothing => true, :status => 200, :content_type => 'text/html' }
end
end
It does not loop through; it goes through it one time and stops. I don't understand what's happening.
This is the content of params[:order]
params[:order] = {ActionController::Parameters} ActionController::Parameters (1 element)
'0' = Array (3 elements)
[0] = "7"
[1] = "5"
[2] = "3"
And if I make a @timeline_order.inspect I get this:
{"0"=>["7", "5", "3"]}
How can I loop through it? I have no idea
@t_order["0"].each?