Tag: 分隔符

将逗号转换为点作为分隔符

如何将用户数输入从11,5转换为11.5? 我尝试了以下作为回调: before_validation :comma_to_delimiter def comma_to_delimiter self.price.to_s.gsub(‘,’, ‘.’).to_f end 但这不起作用。 我希望用户能够输入他想要的任何分隔符 – 当前,当用户使用逗号而不是点时,应用程序会抛出错误。

‘DELIMITER $$’附近的错误

当我从mysql控制台或MySQL Workbench更改Delimeter时我没有收到任何错误,但当我在轨道上的ruby中嵌入相同的代码时出现错误 mysql> DELIMITER $$ mysql> 没有错误。 但 ActiveRecord::Base.connection.execute(%Q{ DELIMITER $$ }) 得到: ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘DELIMITER $$’ at line 1: