add category field to pools
This commit is contained in:
@@ -3,6 +3,7 @@ require 'ostruct'
|
|||||||
class Pool < ActiveRecord::Base
|
class Pool < ActiveRecord::Base
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_format_of :name, :with => /\A[^\s;,]+\Z/, :on => :create, :message => "cannot have whitespace, commas, or semicolons"
|
validates_format_of :name, :with => /\A[^\s;,]+\Z/, :on => :create, :message => "cannot have whitespace, commas, or semicolons"
|
||||||
|
validates_inclusion_of :category, :in => %w(series collection)
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
has_many :versions, :class_name => "PoolVersion", :dependent => :destroy, :order => "pool_versions.id ASC"
|
has_many :versions, :class_name => "PoolVersion", :dependent => :destroy, :order => "pool_versions.id ASC"
|
||||||
@@ -12,7 +13,7 @@ class Pool < ActiveRecord::Base
|
|||||||
before_validation :initialize_creator, :on => :create
|
before_validation :initialize_creator, :on => :create
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
before_destroy :create_mod_action_for_destroy
|
before_destroy :create_mod_action_for_destroy
|
||||||
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :as => [:member, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default]
|
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :category, :as => [:member, :gold, :platinum, :contributor, :janitor, :moderator, :admin, :default]
|
||||||
attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin]
|
attr_accessible :is_deleted, :as => [:janitor, :moderator, :admin]
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
@@ -20,6 +21,14 @@ class Pool < ActiveRecord::Base
|
|||||||
where("is_deleted = false")
|
where("is_deleted = false")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def series
|
||||||
|
where("category = ?", "series")
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection
|
||||||
|
where("category = ?", "collection")
|
||||||
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = scoped
|
q = scoped
|
||||||
params = {} if params.blank?
|
params = {} if params.blank?
|
||||||
@@ -54,6 +63,12 @@ class Pool < ActiveRecord::Base
|
|||||||
q = q.order("updated_at desc")
|
q = q.order("updated_at desc")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:category] == "series"
|
||||||
|
q = q.series
|
||||||
|
elsif params[:category] == "collection"
|
||||||
|
q = q.collection
|
||||||
|
end
|
||||||
|
|
||||||
q
|
q
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -236,7 +251,7 @@ class Pool < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_version
|
def create_version
|
||||||
if post_ids_changed? || name_changed? || description_changed? || is_active_changed? || is_deleted_changed?
|
if post_ids_changed? || name_changed? || description_changed? || is_active_changed? || is_deleted_changed? || category_changed?
|
||||||
last_version = versions.last
|
last_version = versions.last
|
||||||
|
|
||||||
if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id
|
if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<%= f.input :name, :input_html => { :value => @pool.pretty_name } %>
|
<%= f.input :name, :input_html => { :value => @pool.pretty_name } %>
|
||||||
<%= f.input :description %>
|
<%= f.input :description %>
|
||||||
<%= f.input :post_ids, :label => "Posts" %>
|
<%= f.input :post_ids, :label => "Posts" %>
|
||||||
|
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
|
||||||
<%= f.input :is_active %>
|
<%= f.input :is_active %>
|
||||||
<%= f.button :submit %>
|
<%= f.button :submit %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<h1>New Pool</h1>
|
<h1>New Pool</h1>
|
||||||
<%= f.input :name %>
|
<%= f.input :name %>
|
||||||
<%= f.input :description %>
|
<%= f.input :description %>
|
||||||
|
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
|
||||||
<%= f.button :submit %>
|
<%= f.button :submit %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
6
db/migrate/20130506154136_add_category_to_pools.rb
Normal file
6
db/migrate/20130506154136_add_category_to_pools.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class AddCategoryToPools < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
execute("set statement_timeout = 0")
|
||||||
|
add_column :pools, :category, :string, :null => false, :default => "series"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user