Commit b13acb431553bfea14046207b0be1c4d751afe98

Authored by Rodrigo Souto
1 parent 5954b097

Adding list of searchable items for models

app/controllers/application_controller.rb
@@ -154,8 +154,8 @@ class ApplicationController < ActionController::Base @@ -154,8 +154,8 @@ class ApplicationController < ActionController::Base
154 end 154 end
155 end 155 end
156 156
157 - def find_by_contents(klass, query, paginate_options{}, options={})  
158 - @plugins.first(:find_by_contents, klass, query, paginate_options, options) || 157 + def find_by_contents(klass, query, paginate_options={}, options={})
  158 + @plugins.first(:find_by_contents, klass, query, paginate_options, options)# ||
159 # Failback search using like 159 # Failback search using like
160 end 160 end
161 161
app/models/article.rb
@@ -2,6 +2,14 @@ require 'hpricot' @@ -2,6 +2,14 @@ require 'hpricot'
2 2
3 class Article < ActiveRecord::Base 3 class Article < ActiveRecord::Base
4 4
  5 + SEARCHABLE_FIELDS = {
  6 + :name => 10,
  7 + :abstract => 3,
  8 + :body => 2,
  9 + :slug => 1,
  10 + :filename => 1,
  11 + }
  12 +
5 track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? } 13 track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? }
6 14
7 # xss_terminate plugin can't sanitize array fields 15 # xss_terminate plugin can't sanitize array fields
app/models/category.rb
1 class Category < ActiveRecord::Base 1 class Category < ActiveRecord::Base
2 2
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :acronym => 5,
  6 + :abbreviation => 5,
  7 + :slug => 1,
  8 + }
  9 +
3 validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n 10 validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n
4 validates_presence_of :name, :environment_id 11 validates_presence_of :name, :environment_id
5 validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n 12 validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n
app/models/certifier.rb
1 class Certifier < ActiveRecord::Base 1 class Certifier < ActiveRecord::Base
2 2
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :description => 3,
  6 + :link => 1,
  7 + }
  8 +
3 belongs_to :environment 9 belongs_to :environment
4 10
5 has_many :qualifier_certifiers, :dependent => :destroy 11 has_many :qualifier_certifiers, :dependent => :destroy
app/models/comment.rb
1 class Comment < ActiveRecord::Base 1 class Comment < ActiveRecord::Base
2 2
  3 + SEARCHABLE_FIELDS = {
  4 + :title => 10,
  5 + :name => 4,
  6 + :body => 2,
  7 + }
  8 +
3 validates_presence_of :body 9 validates_presence_of :body
4 10
5 belongs_to :source, :counter_cache => true, :polymorphic => true 11 belongs_to :source, :counter_cache => true, :polymorphic => true
app/models/license.rb
1 class License < ActiveRecord::Base 1 class License < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :url => 5,
  6 + }
  7 +
2 belongs_to :environment 8 belongs_to :environment
3 has_many :content, :class_name => 'Article', :foreign_key => 'license_id' 9 has_many :content, :class_name => 'Article', :foreign_key => 'license_id'
4 10
app/models/national_region.rb
1 class NationalRegion < ActiveRecord::Base 1 class NationalRegion < ActiveRecord::Base
2 2
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 1,
  5 + :national_region_code => 1,
  6 + }
  7 +
3 def self.search_city(city_name, like = false, state = nil) 8 def self.search_city(city_name, like = false, state = nil)
4 9
5 operator = "=" 10 operator = "="
app/models/product.rb
1 class Product < ActiveRecord::Base 1 class Product < ActiveRecord::Base
2 2
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 10,
  5 + :description => 1,
  6 + }
  7 +
3 belongs_to :enterprise 8 belongs_to :enterprise
4 has_one :region, :through => :enterprise 9 has_one :region, :through => :enterprise
5 validates_presence_of :enterprise 10 validates_presence_of :enterprise
app/models/profile.rb
@@ -3,6 +3,12 @@ @@ -3,6 +3,12 @@
3 # which by default is the one returned by Environment:default. 3 # which by default is the one returned by Environment:default.
4 class Profile < ActiveRecord::Base 4 class Profile < ActiveRecord::Base
5 5
  6 + SEARCHABLE_FIELDS = {
  7 + :name => 10,
  8 + :identifier => 5,
  9 + :nickname => 2,
  10 + }
  11 +
6 module Roles 12 module Roles
7 def self.admin(env_id) 13 def self.admin(env_id)
8 find_role('admin', env_id) 14 find_role('admin', env_id)
app/models/qualifier.rb
1 class Qualifier < ActiveRecord::Base 1 class Qualifier < ActiveRecord::Base
2 2
  3 + SEARCHABLE_FIELDS = {
  4 + :name => 1,
  5 + }
  6 +
3 belongs_to :environment 7 belongs_to :environment
4 8
5 has_many :qualifier_certifiers, :dependent => :destroy 9 has_many :qualifier_certifiers, :dependent => :destroy
app/models/scrap.rb
1 class Scrap < ActiveRecord::Base 1 class Scrap < ActiveRecord::Base
  2 + SEARCHABLE_FIELDS = {
  3 + :content => 1,
  4 + }
2 validates_presence_of :content 5 validates_presence_of :content
3 validates_presence_of :sender_id, :receiver_id 6 validates_presence_of :sender_id, :receiver_id
4 7