升级到Rails 4.1获取错误:ArgumentError:未知密钥::订单

Tux*_*son 5 ruby activerecord ruby-on-rails upgrade

我正处于升级过程中,遇到了一些问题.

这是我的错误:

/Users/jay/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/core_ext/hash/keys.rb:71:in`block in assert_valid_keys':未知密钥::订单.有效密钥为:: class_name,:class,:foreign_key,:validate,:autosave,:table_name,:before_add,:after_add,:before_remove,:after_remove ,:extend,: primary_key ,: dependent,:as,:through,: source,:source_type,:inverse_of,:counter_cache,:join_table(ArgumentError)

它与我的示波器有关吗?例如:

scope :total_views, order('total_views DESC')

要么

default_scope { order: :sort_order }

要么

scope :recent, order: 'created_at desc'

我有一堆使用顺序的范围,发生了什么?

spi*_*ann 2

Rails 4 中的命名范围现在采用 lambda 而不是哈希值。在 lambda 中使用新的查询语法而不是旧的哈希语法:

default_scope { order(:sort_order) } 

scope :total_views, -> { order('total_views DESC') }
scope :recent,      -> { order('created_at DESC') }
Run Code Online (Sandbox Code Playgroud)

了解有关 ActiveRecord 查询的更多信息:http://edgeguides.rubyonrails.org/active_record_querying.html#scopes