这是 中的update动作notes_controller.rb。
def update
note = current_user.notes.find(params[:id])
note.update_attributes! params[:note]
render json: {note: note.display}
end
它工作正常。
我的note对象有一个datetime名为scheduled_time. 当JSON数据从update客户端的操作返回时,我需要知道注释更新的日期是否scheduled_time与update.
def update
note = current_user.notes.find(params[:id])
previous_date = note.scheduled_time.to_date
note.update_attributes! params[:note]
date_changed = previous_date != note.scheduled_time.to_date
render json: {note: note.display, date_changed: date_changed}
end
但是添加此代码会导致JSONdata( note.display) 中返回的注释包含update_attributes!. update_attributes!仍然有效,但从操作返回的数据JSON不update反映更新。为什么会发生这种情况?
我正在使用
Rails 3.2.0
ruby 1.9.3
我也通常在笔记模型中使用Memoistdisplay gem,但没有具体使用方法。