Skip to content

Instantly share code, notes, and snippets.

@Grandvizir
Created March 19, 2015 12:09
Show Gist options
  • Save Grandvizir/a9a27f9a24b341883318 to your computer and use it in GitHub Desktop.
Save Grandvizir/a9a27f9a24b341883318 to your computer and use it in GitHub Desktop.
Project
class Project < ActiveRecord::Base
track_who_does_it
belongs_to :organization
has_many :teams, :dependent => :destroy
has_many :trackers, :dependent => :destroy
has_many :layouts, :dependent => :destroy
accepts_nested_attributes_for :trackers, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
accepts_nested_attributes_for :layouts
validate :is_respecting_plan, on: [:create]
validates :name, :presence => true, uniqueness: true, :format => { with: /\w+/, message: :only_word_character }
protected
def self.project_path
'/dashboard/projects'
end
def is_respecting_plan
plan = self.organization.plan
if !( plan.project_count > self.organization.projects.count ) && plan.project_count != -1
errors.add('plans.limit', 'You have reached the number of projects included in your plan' )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment