现在我有一个控制器:
class CommonController < ApplicationController
def location
@locations=Location.select(:key)
render json: @locations
end
end
我的数据库是mysql
,key
是mysql关键字。
但是我的表juest有一个名为key
当我运行动作时。我收到错误:
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 'key FROM `locations`' at line 1: SELECT key FROM `locations`
那我该怎么办?
答案 0 :(得分:0)
我明白了。就这样写:
@locations=Location.select('`key`')