Adds User.organization_attributes

This commit is contained in:
kikito
2015-08-16 23:35:56 +02:00
parent 60a1cc2267
commit 9343952d52
3 changed files with 22 additions and 29 deletions

View File

@@ -2,6 +2,8 @@ class Organization < ActiveRecord::Base
belongs_to :user
validates :name, presence: true
delegate :email, :phone_number, to: :user
def verify
@@ -22,5 +24,4 @@ class Organization < ActiveRecord::Base
(verified_at.blank? || verified_at < rejected_at)
end
end

View File

@@ -4,15 +4,18 @@ class User < ActiveRecord::Base
acts_as_voter
validates :first_name, presence: true, if: :use_first_name?
validates :last_name, presence: true, if: :use_last_name?
validates :nickname, presence: true, if: :use_nickname?
validates :organization_name, presence: true, if: :is_organization
has_one :administrator
has_one :moderator
has_one :organization
validates :first_name, presence: true, if: :use_first_name?
validates :last_name, presence: true, if: :use_last_name?
validates :nickname, presence: true, if: :use_nickname?
validates_associated :organization, message: false
accepts_nested_attributes_for :organization
scope :administrators, -> { joins(:administrators) }
scope :moderators, -> { joins(:moderator) }
scope :organizations, -> { joins(:organization) }
@@ -50,15 +53,10 @@ class User < ActiveRecord::Base
private
def use_first_name?
!is_organization && !use_nickname?
!organization? && !use_nickname?
end
def use_last_name?
use_first_name?
end
def create_associated_organization
create_organization(name: organization_name) if is_organization
end
end