0

我有一个 Locations 表,里面有 4 个位置。架构如下:

create_table "locations", :force => true do |t|
    t.string   "name"
    t.string   "address"
    t.string   "city"
    t.string   "state"
    t.string   "zip"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
  end

我在 ajax 调用中运行它,它Location在下面的 puts 行中不断返回。

@current_location = Location.where('lower(name) = ?', params[:id][1..-1].humanize.downcase)     
p "@current_location = #{@current_location}"

params[:id][1..-1].humanize.downcase解释为'brooklyn park'

我实际上并没有在日志文件中找到这个查询,当我将活动记录复制并粘贴到 rails 控制台时,它似乎工作得很好。

为什么总是返回'Location'

4

1 回答 1

1

代替

@current_location = Location.where('lower(name) = ?', params[:id][1..-1].humanize.downcase)

@current_location = Location.where('lower(name) = ?', params[:id][1..-1].humanize.downcase).first
于 2013-03-13T05:45:42.087 回答