sách gpt4 ai đã đi

mysql - 删除存储在 MySQL 中的文本的额外附加字符

In lại 作者:行者123 更新时间:2023-11-29 00:24:24 25 4
mua khóa gpt4 Nike

我有一个 api Controller ,它从 api 用户那里收集信息。但是,某些用户信息在发送和存储在 MySQL 数据库中时有时会显示添加下划线,例如 "this is a test ________" Còn hơn là this is a test。然而,当通过浏览器运行时,它存储得很好。

可能是什么问题。

Controller 摘录;

@message.message = CGI.unescape(params[:message]).strip

作为临时修复,任何想法我都可以删除在存储中或消息到达时添加到消息中的所有 6 个下划线。

class Api::V1::Json::MessagesController < ApplicationController
before_filter :authenticate
require 'uri'
require 'cgi'
def sms
@message = Message.new
#@message.to = decoded_to.gsub(/[^\d]/,"")
@message.to = CGI.unescape(params[:to]).strip.gsub("+","").gsub(/\s+/, "")
@message.from = CGI.unescape(params[:from])
@message.message = CGI.unescape(params[:message]).strip
@message.user_id = current_user.id
@message.status = 'Queued'
if @message.save
MessageWorker.perform_async(@message.id, [""], current_user.id)
render json: {status: "Success"}
khác
render json: {status: "Failed" }
kết thúc
kết thúc

riêng tư

def authenticate
error!('Unauthorized. Invalid token.', 401) unless current_user
kết thúc

def current_user
# find token. Check if valid.
user_token = params[:token]
token = ApiKey.where(:access_token => user_token).first
if token
@current_user = User.find(token.user_id)
khác
SAI
kết thúc
kết thúc
kết thúc

模型是;

class Message < ActiveRecord::Base
attr_accessible :message, :phone, :status, :to, :from, :user_id
attr_accessor :schedule
validates :message, :presence => true
validates :from, :presence => true
validates :to, :presence => true
validates :status, :presence => true
validates_length_of :message, :maximum => 1600, :allow_blank => true
validates_length_of :from, :maximum => 11, :allow_blank => false
belongs_to :user

1 Câu trả lời

像这样改变你的模型

class Message < ActiveRecord::Base

before_save :strip_underscore

def strip_underscore
self.message.gsub("______","")
kết thúc

kết thúc

关于mysql - 删除存储在 MySQL 中的文本的额外附加字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19633454/

25 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com