diff options
author | spag <spag@golwen.net> | 2012-12-29 17:42:35 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2012-12-29 17:42:35 +0100 |
commit | 5cf46b6467679ea0367cc0c00787f6f1c86560e4 (patch) | |
tree | b3f314d1ba574e328f1ce5a27aeadb6ae32980d5 /app/controllers | |
parent | 929e7a391f139ed827e9bd3bea339789a82de6d4 (diff) | |
parent | 8d20201910b1915cffa495e6474d50f9c8e8331d (diff) |
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/phones_controller.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index b865cb1..f1dcd3e 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -13,9 +13,10 @@ class PhonesController < ApplicationController end def new - used_sip_account_ids = Phone.where('fallback_sip_account_id IS NOT NULL').collect {|r| r.fallback_sip_account } - @fallback_sip_accounts = SipAccount.where('sip_accountable_type = "Tenant" AND id NOT IN (?)', used_sip_account_ids).all + set_fallback_sip_accounts + @phone = @phoneable.phones.build() + # Use the last phone.phone_model as the default. # @phone.phone_model_id = Phone.last.try(:phone_model).try(:id) @@ -31,13 +32,13 @@ class PhonesController < ApplicationController m = method( :"#{@phoneable.class.name.underscore}_phone_path" ) redirect_to m.( @phoneable, @phone ), :notice => t('phones.controller.successfuly_created') else + set_fallback_sip_accounts render :new end end def edit - used_sip_account_ids = Phone.where('fallback_sip_account_id IS NOT NULL AND id != ?', @phone.id).collect {|r| r.fallback_sip_account_id } - @fallback_sip_accounts = SipAccount.where('sip_accountable_type = "Tenant" AND id NOT IN (?)', used_sip_account_ids).all + set_fallback_sip_accounts end def update @@ -75,5 +76,10 @@ class PhonesController < ApplicationController add_breadcrumb @phone, method( :"#{@phone.phoneable.class.name.underscore}_phone_path" ).(@phone.phoneable, @phone) end end + + def set_fallback_sip_accounts + used_sip_account_ids = Phone.where(:fallback_sip_account_id => SipAccount.pluck(:id)).pluck(:fallback_sip_account_id) + @fallback_sip_accounts = SipAccount.where(:sip_accountable_type => 'Tenant').where(:hotdeskable => true) - SipAccount.where(:id => used_sip_account_ids) + end end |