[fixed #377] Fixed Group.by_admin scope.

This commit is contained in:
George Vinogradov 2012-04-03 17:08:22 +04:00
parent b769bc1783
commit fe053537c3
2 changed files with 3 additions and 3 deletions

View File

@ -21,7 +21,7 @@ class Group < ActiveRecord::Base
scope :search, lambda {|q| where("uname ILIKE ?", "%#{q.strip}%")}
scope :opened, where('1=1')
scope :by_owner, lambda {|owner| where(:owner_id => owner.id)}
scope :by_admin, lambda {|admin| joins(:relations).where(:'relations.role' => 'admin', :'relations.target_id' => admin.id, :'relations.target_type' => 'User')}
scope :by_admin, lambda {|admin| joins(:objects).where(:'relations.role' => 'admin', :'relations.object_id' => admin.id, :'relations.object_type' => 'User')}
attr_accessible :description
attr_readonly :own_projects_count
@ -34,7 +34,7 @@ class Group < ActiveRecord::Base
# include Modules::Models::Owner
def self.can_own_project(user)
(by_owner(user) | by_admin(user)).collect { |el| [el.name, el.id] }
(by_owner(user) | by_admin(user))
end
def name

View File

@ -17,7 +17,7 @@
= label_tag t("activerecord.attributes.project.who_owns.group")
= radio_button_tag :who_owns, 'group', @who_owns == :group #{}.merge( (@who_owns == :group) ? {:checked => 'checked'} : {} )
-# TODO: Make our own select_box helper with new design, blackjack and bitches!
= select_tag :owner_id, options_for_select( Group.can_own_project(current_user) )
= select_tag :owner_id, options_from_collection_for_select( Group.can_own_project(current_user), :id, :name )
- else
= hidden_field_tag :who_owns, :me
.both