diff --git a/app/controllers/enterprise_controller.rb b/app/controllers/enterprise_controller.rb index b93fe0c..e154440 100644 --- a/app/controllers/enterprise_controller.rb +++ b/app/controllers/enterprise_controller.rb @@ -2,7 +2,8 @@ class EnterpriseController < ApplicationController def index - @my_enterprises = current_user.enterprises + @my_enterprises = current_user.enterprises if current_user + @enterprises = Enterprise.find(:all) - @my_enterprises end def register @@ -21,6 +22,7 @@ class EnterpriseController < ApplicationController def create @enterprise = Enterprise.new(params[:enterprise]) + @enterprise.manager = current_user if @enterprise.save flash[:notice] = _('Enterprise was succesfully created') redirect_to :action => 'register' diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e443105..851ae76 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -6,6 +6,7 @@ class Enterprise < ActiveRecord::Base end has_one :enterprise_profile, :class_name => 'Profile', :as => :profile_owner + has_many :affiliations has_many :users, :through => :affiliation belongs_to :manager, :class_name => 'User' diff --git a/app/models/user.rb b/app/models/user.rb index 7b1a9ff..c5ef68a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,7 +10,7 @@ class User < ActiveRecord::Base has_one :personal_profile, :class_name => 'Profile', :as => :profile_owner has_many :affiliations - has_many :enterprises, :through => :affiliation + has_many :enterprises, :through => :affiliations # Virtual attribute for the unencrypted password attr_accessor :password -- libgit2 0.21.2