0
我正嘗試在事件模型上創建全文搜索。 該模型包含country_code字段,其中存儲國家代碼; 我希望能夠按國家直接輸入國家名稱,比方說法國而不是法國。使用虛擬屬性搜索
我的範圍是這樣的:
pg_search_scope :full_search, against: [:name, :city, :country], associated_against: {
event_type: [:name],
dance_types: [:name]
}
我有一個國家的方法
def country
return '' if country_code.blank?
country = ISO3166::Country[country_code]
(country.translations[I18n.locale.to_s] || country.name) unless country.nil?
end
不幸的是叫我的搜索範圍產生以下錯誤:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column events.country does not exist.
如何解決這個?
感謝您的回覆。 我的活動模型沒有country_code字段的國家/地區字段。 我正在使用gem country_select,因此我不需要存儲完整的國家/地區名稱,也不必爲國家/地區提供單獨的表格。這就是爲什麼我只有一個國家的contry_code字段。 國家方法的作用是返回給定country_code的國家名稱 – user1445685