Reputation: 13
Im really really new to ruby/ruby on rails and was given a model class that looks like this. I just want ask why is it giving me odd number list for Hash error when I try to call Ranks.search_word("Jagger")
Im using 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
Upvotes: 1
Views: 308
Reputation: 16752
You have an additional Pair of curly brackets which are not required. Try:
named_scope :search_word, lambda{ |keyword|
if keyword.present?
{:conditions => { :CM_CHAR_ATLAS => {:char_name => keyword }} }
else
{}
end
}
Upvotes: 1