I have a model Question which has_many Options.
In an action I modify the Options of the a Question object and then return the Question object as a json. (This is used in an ajax call). The problem is, the returned json is not up to date and doesn’t reflect the modifications I made.
def action
question = Question.find(:id)
question.options.each do |op|
op.blah += 1
end
respond_to do |format|
if question.save()
format.json { render json: {question: question.to_json(:include => :options)} }
else
blah blah
end
end
end
Weird because you edit the items in place, then save (and verified that they are saved to db –since refresh works). So the render to json should work.
You could always do explict
reloadcalls, likeBut it would be very weird if that would be the cause, since you actually just saved that data.
But yesterday I had a similar problem, and actually what happened that I did a
replaceHtmlof adiv, but my inserted data did not have the same surroundingdiv. So the first time it updated correctly, and the second time it just showed the old data (while in fact it did nothing, because it did not find the div to replace).So in short: if simply refreshing works, imho it is not the database and it is not caching, but will most likely be something in your javascript: the updating of the screen that is going wrong.
Hope this helps.