これは の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のアクションからデータが返されたら、メモの更新日が.updatescheduled_timeupdate
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
JSONしかし、このコードを追加すると、 data( note.display)で返されるメモに、update_attributes!. はupdate_attributes!引き続き機能しますがJSON、アクションから返されたデータにupdateは更新が反映されていません。なぜこれが起こるのでしょうか?
私は使用しています
Rails 3.2.0
ruby 1.9.3
また、ノートモデルでは一般的にMemoist gemを使用していますが、display特にメソッドでは使用していません。