0

现在我有一个控制器:

class CommonController < ApplicationController
  def location
    @locations=Location.select(:key)
    render json: @locations
  end
end

我的数据库是mysql,并且key是 mysql 关键字。

但是我的表只是有一个名为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` 

所以我该怎么做?

4

1 回答 1

0

我明白了。就这样写吧:

@locations=Location.select('`key`')
于 2013-10-25T07:17:15.263 回答