36 lines
600 B
Ruby
36 lines
600 B
Ruby
# -*- encoding : utf-8 -*-
|
|
class Article < ActiveRecord::Base
|
|
belongs_to :image_file
|
|
belongs_to :folder
|
|
|
|
|
|
after_create :after_creation
|
|
|
|
|
|
|
|
has_one :block, :as => :blockable
|
|
|
|
belongs_to :folder
|
|
|
|
validates :title, :presence => true
|
|
validates :slug, :presence => true, :uniqueness => {:scope => :folder_id}
|
|
|
|
def after_creation
|
|
@block = Block.new(:block_name => "Contenu")
|
|
@block.blockable = self
|
|
@block.save
|
|
|
|
ContentType.all.each do |content_type|
|
|
@block.content_types << content_type
|
|
|
|
end
|
|
|
|
end
|
|
|
|
before_validation do
|
|
self.slug = self.slug.to_slug
|
|
|
|
end
|
|
|
|
end
|