Extract data fetching from views

This commit is contained in:
Rohan Mitchell
2015-02-20 11:17:01 +11:00
parent 98063dae60
commit 176db78e64
2 changed files with 11 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
module Admin
class EnterpriseGroupsController < ResourceController
before_filter :load_countries, :except => :index
before_filter :load_data, except: :index
before_filter :load_object_data, only: [:new, :edit, :create, :update]
def index
@enterprise_groups = @enterprise_groups.managed_by(spree_current_user)
@@ -34,10 +35,16 @@ module Admin
private
def load_countries
def load_data
@countries = Spree::Country.order(:name)
@enterprises = Enterprise.activated
end
def load_object_data
@owner_email = @enterprise_group.andand.owner.andand.email || ""
end
def collection
EnterpriseGroup.by_position
end

View File

@@ -17,8 +17,7 @@
.with-tip{'data-powertip' => "The primary user responsible for this group."}
%a What's this?
.eight.columns.omega
- owner_email = @enterprise_group.andand.owner.andand.email || ""
= f.hidden_field :owner_id, class: "select2 fullwidth", 'ofn-user-autocomplete' => true, email: owner_email
= f.hidden_field :owner_id, class: "select2 fullwidth", 'ofn-user-autocomplete' => true, email: @owner_email
= f.field_container :on_front_page do
= f.label :on_front_page, 'On front page?'
@@ -28,7 +27,7 @@
= f.field_container :enterprise_ids do
= f.label :enterprise_ids, 'Enterprises'
%br/
= f.collection_select :enterprise_ids, Enterprise.activated, :id, :name, {}, {class: "select2 fullwidth", multiple: true}
= f.collection_select :enterprise_ids, @enterprises, :id, :name, {}, {class: "select2 fullwidth", multiple: true}
%fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='About'" } }
%legend About