5
votes

i'm in the middle of my upgrade and am running into some problems.

Here is my error:

/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': Unknown key: :order. Valid keys are: :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)

Does it have something to do with my scopes? For example:

scope :total_views, order('total_views DESC')

or

default_scope { order: :sort_order }

or

scope :recent, order: 'created_at desc'

I have bunch of scopes that use order, what is going on?

3
I had this problem, and I think it has it's roots in acts_as_tree. - mcr

3 Answers

2
votes

Named scopes in Rails 4 take lambdas now instead of hashes. Within a lambda use the new query syntax and not the old hash syntax:

default_scope { order(:sort_order) } 

scope :total_views, -> { order('total_views DESC') }
scope :recent,      -> { order('created_at DESC') }

Read more about ActiveRecord querying: http://edgeguides.rubyonrails.org/active_record_querying.html#scopes

0
votes

Your scopes need to be in the form of a lambda.

scope :total_views, -> { order('total_views DESC') }

default_scope -> { order: :sort_order }

scope :recent, -> { order: 'created_at desc' }

0
votes

I upgraded acts_as_tree to version 2.1.0, and the problem went away.