1

我对 ruby​​/ruby on rails 真的很陌生,并且得到了一个看起来像这样的模型类。我只是想问为什么当我尝试调用 Ranks.search_word("Jagger") 时它会给我哈希错误的奇数列表

我正在使用 Rails 2.3.5/ActiveRecord 2.3.5

class Ranks < ActiveRecord::Base
  set_table_name 'CM_GT_RANK'
  set_primary_key 'rank_id'

  has_one :character_atlas, :class_name => "CharAtlas", :foreign_key => "char_id_db"
  has_one :player_records, :class_name => "PlayerRecord", :foreign_key => "char_id"

  default_scope  :joins => :character_atlas,
                 :order => "rank asc"
  named_scope :search_word,
    lambda{ |keyword|
      {
        if keyword.present?
          {:conditions => { :CM_CHAR_ATLAS => {:char_name => keyword }} }
        else
          {}
        end
      }
  }
end
4

1 回答 1

1

您还有一对不需要的大括号。尝试:

named_scope :search_word, lambda{ |keyword|
  if keyword.present?   
    {:conditions => { :CM_CHAR_ATLAS => {:char_name => keyword }} }
  else
    {}
  end
}
于 2013-01-07T10:27:38.627 回答