add category field to pools

This commit is contained in:
Toks 2013-05-06 12:14:42 -04:00
parent 1d56f237a8
commit a9efb93e99
4 changed files with 25 additions and 2 deletions

View File

@ -3,6 +3,7 @@ require 'ostruct'
class Pool < ActiveRecord::Base
validates_uniqueness_of :name
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 :updater, :class_name => "User"
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
after_save :create_version
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]
module SearchMethods
@ -20,6 +21,14 @@ class Pool < ActiveRecord::Base
where("is_deleted = false")
end
def series
where("category = ?", "series")
end
def collection
where("category = ?", "collection")
end
def search(params)
q = scoped
params = {} if params.blank?
@ -54,6 +63,12 @@ class Pool < ActiveRecord::Base
q = q.order("updated_at desc")
end
if params[:category] == "series"
q = q.series
elsif params[:category] == "collection"
q = q.collection
end
q
end
end
@ -236,7 +251,7 @@ class Pool < ActiveRecord::Base
end
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
if last_version && CurrentUser.ip_addr == last_version.updater_ip_addr && CurrentUser.id == last_version.updater_id

View File

@ -5,6 +5,7 @@
<%= f.input :name, :input_html => { :value => @pool.pretty_name } %>
<%= f.input :description %>
<%= f.input :post_ids, :label => "Posts" %>
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
<%= f.input :is_active %>
<%= f.button :submit %>
<% end %>

View File

@ -4,6 +4,7 @@
<h1>New Pool</h1>
<%= f.input :name %>
<%= f.input :description %>
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
<%= f.button :submit %>
<% end %>
</div>

View 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