48 lines
958 B
Ruby
Executable File
48 lines
958 B
Ruby
Executable File
class Petition < ActiveRecord::Base
|
|
#attr_accessible :description, :enabled, :name, :slug
|
|
|
|
def name
|
|
self.petition_langs.first.title
|
|
end
|
|
|
|
has_many :petition_langs, :dependent => :destroy
|
|
|
|
accepts_nested_attributes_for :petition_langs
|
|
|
|
|
|
after_create :after_creation
|
|
|
|
|
|
has_many :blocks, :as => :blockable
|
|
|
|
belongs_to :image_file
|
|
|
|
def after_creation
|
|
LangSite.all.each do |lang|
|
|
@block = Block.new(:block_name => "Contenu", :lang_site => lang)
|
|
@block.blockable = self
|
|
@block.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def alloweds_types
|
|
self.block.allow_types :TitleContent, :TextContent, :ImageContent, :LinkContent, :GalleryContent, :HtmlContent
|
|
|
|
end
|
|
|
|
has_many :signators, :class_name => "PetitionSignator"
|
|
|
|
def signators_number
|
|
self.signators.count
|
|
|
|
end
|
|
|
|
def confirmed_signators_number
|
|
self.signators.where(:enabled => true).count
|
|
|
|
end
|
|
|
|
end
|