returnrender_error(YiffyAPIErrorCodes::SHORTENER_NO_CHANGES,message:"No changes were detected.")unless@short_url.saved_change_to_url?||@short_url.saved_change_to_creator_name?
returnrender_error(YiffyAPIErrorCodes::SHORTENER_CODE_TOO_LONG,message:error,errors:@short_url.errors.full_messages)iferror.to_s=~/Code is too long/
returnrender_error(YiffyAPIErrorCodes::SHORTENER_INVALID_CODE,message:error,errors:@short_url.errors.full_messages)iferror.to_s=~/Code is invalid/
returnrender_error(YiffyAPIErrorCodes::SHORTENER_INVALID_URL,message:error,errors:@short_url.errors.full_messages)iferror.to_s=~/Url is invalid/
returnrender_error(YiffyAPIErrorCodes::SHORTENER_URL_TOO_LONG,message:error,errors:@short_url.errors.full_messages)iferror.to_s=~/Url is too long/
returnrender_error(YiffyAPIErrorCodes::SHORTENER_CREDIT_TOO_LONG,message:error,errors:@short_url.errors.full_messages)iferror.to_s=~/Creator name is too long/
returnrender_error(YiffyAPIErrorCodes::SHORTENER_CODE_IN_USE,message:error,errors:@short_url.errors.full_messages)iferror.to_s=~/Code has already been taken/
@short_url.save!# Make further failed validations raise
end
end
end
defload_shorturl
@short_url=ShortUrl.find_by(code:params[:code])
render_error(YiffyAPIErrorCodes::SHORTENER_NOT_FOUND,message:"A short url with that code was not found.")if@short_url.nil?
returnrender_error(YiffyAPIErrorCodes::SHORTENER_NO_MANAGEMENT_CODE,message:"That short url cannot be edited by you.")if@short_url.management_code.blank?||management_code.blank?
render_error(YiffyAPIErrorCodes::SHORTENER_MANAGEMENT_CODE_MISMATCH,message:"That management code does not match this short url.")ifmanagement_code!=@short_url.management_code