app/controllers/versions_controller.rb
# test if someone else has edited the same item to undo
test if someone else has edited the same item to undo
test if someone else has edited the same item to undo
def conflict?
    @version = Version.find_by_id(params[:id])
    if @version
      @versions = Version.where(["whodunnit = ? AND created_at = ?", @version.version_author, @version.created_at])
      @versions.each do |v|
        next unless v.item
        if v.item.versions.last.whodunnit.to_i != session[:user].id
          flash[:note] = "User #{User.find(v.item.versions.last.whodunnit).name} has edited this item since your last edit. "
          redirect_to :back
        end
      end
    end
  end
def conflict? @version = Version . find_by_id ( params [ :id ] ) if @version @versions = Version . where ( [ "whodunnit = ? AND created_at = ?" , @version . version_author , @version . created_at ] ) @versions . each do | v | next unless v . item if v . item . versions . last . whodunnit . to_i != session [ :user ] . id flash [ :note ] = "User #{User.find(v.item.versions.last.whodunnit).name} has edited this item since your last edit. " redirect_to :back end end end end
test if someone else has edited the same item to undo
test if someone else has edited the same item to undo