SQLite3:没有这样的列:“id desc”

时间:2015-02-12 09:44:13

标签: ruby-on-rails ruby sqlite

我正在编写一段非常古老的代码(ruby 1.9.3和rails 2.3.12)。我试图为它编写一些测试,这样当我开始升级它时,我知道一切是如何工作的。我现在正用黄瓜写它们,并遇到了一个我似乎无法解决的问题。此问题不会出现在生产版本中,因为一切正常。但是,在开发和测试中,当我尝试单击其中一个链接时,会出现以下错误;

And I click "Trips (1)"         # features/step_definitions/user_management_steps.rb:1
      SQLite3::SQLException: no such column: "id desc": SELECT "trips".* FROM "trips"  INNER JOIN "trips_users" ON "trips".id = "trips_users".trip_id    WHERE (("trips_users".user_id = 1))  ORDER BY ["id desc"] LIMIT 10 OFFSET 0 (ActiveRecord::StatementInvalid)
      ./vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:157:in `find'
      ./app/controllers/users_controller.rb:259:in `trips'
      /home/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
      <internal:prelude>:10:in `synchronize'
      ./features/step_definitions/user_management_steps.rb:2:in `/^I click "([^"]*)"$/'
      features/trips.feature:30:in `And I click "Trips (1)"'

我到处寻找,找不到任何对

的引用
no such column: "id desc"

有谁知道这意味着什么?

为什么这会在开发和测试环境中中断,而不是在生产环境中?

非常感谢任何帮助!

*编辑

的Gemfile;

source 'https://rubygems.org'

gem "rails", "~> 2.3.12"

gem "airbrake"
gem "aws-s3"
gem "bj"
gem "calendar_date_select", "1.15"
gem "cancan", "1.2.0"
gem "carmen"
gem 'comma', '0.4.1'
gem 'exifr'
gem "factory_girl", "1.2.4"
gem 'fastercsv'
gem "geokit"
gem "haml"
gem "hpricot"
gem 'hoptoad_notifier'
gem "jrails"
gem "libxml-ruby", "2.4.0"
gem "memcached", "~> 1.8.0"
gem "mysql2", "~> 0.2.6"
gem "rake", "0.8.3"
gem 'recurly'
gem "rdoc"
gem "rmagick"
gem "rspreedly"
gem "rubyzip"
gem 'sass'
#need to use simplecov when upgrading to ruby 2 as rcov doesn't work
gem "simplecov"
gem 'sqlite3'
gem "will_paginate", "2.3.16"
gem 'yaml_db'

group :development, :test do
  gem 'test-unit', '1.2.3'
  gem 'rspec', '1.3.2'
  gem 'rspec-rails', '~> 1.3.4'
end

group :test do
  gem 'capybara', '0.3.5'
  gem 'cucumber', '1.1.2'
  gem 'cucumber-rails', :git => "git://github.com/RKelln/cucumber-rails.git", :branch => "0.3.2-capybara-fix"
  gem 'database_cleaner'
end

user_controller.rb;

class UsersController < ApplicationController

  before_filter :find_user
  load_and_authorize_resource :except => [:news, :search, :update, :mobile_new, :mobile_success]
  before_filter :authorise, :only => [:export_to_csv]

  def find_user
    begin
      @user = User.find_by_login(params[:id])
    rescue
      @user = User.find(params[:id])
    end
  end

....
....
def trips
    body_attributes "view-followers", 'main-feed', 'Trips'

    @page = (params[:page].to_i || 0)
    @page = 1 if @page == 0
    @trips = @user.trips.reverse_order

    @year = ''
    @month = ''

    unless params[:year].blank?
      @year = params[:year].to_i
      @trips = @trips.select { |trip| trip.start_date.year == @year }
    end

    unless params[:month].blank?
      @month = params[:month].to_i
      @trips = @trips.select { |trip| trip.start_date.month == @month }
    end

    @years = Array.new
    unless @user.trips.empty?
      @years = @user.trips.first.start_date.year..@user.trips.last.start_date.year
    end

    @show_more_link = @trips.count > (10 * @page)
    @trips = @trips.paginate(:per_page => 10, :page => @page)
  end

1 个答案:

答案 0 :(得分:1)

看起来您的Trips查询订单定义为此Trip.order('[id desc]')。正确的格式是(取决于您的Rails版本):

Trip.order('id DESC') 
Trip.order(id: :desc) # works only in Rails >= 4.0