Class: Spree::Admin::HomepageSectionController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/homepage_section_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_resource ⇒ Object

A new section joins the storefront you were viewing. Reading it from the URL keeps tenant_id out of permitted_resource_params, so the form cannot reassign a storefront.



24
25
26
# File 'app/controllers/spree/admin/homepage_section_controller.rb', line 24

def build_resource
  model_class.new(tenant_id: params[:tenant_id].presence)
end

#collection_url ⇒ Object



18
19
20
# File 'app/controllers/spree/admin/homepage_section_controller.rb', line 18

def collection_url
  admin_homepage_feed_homepage_section_index_url(tenant_id: params[:tenant_id].presence || @object&.tenant_id)
end

#edit ⇒ Object



28
29
30
31
32
# File 'app/controllers/spree/admin/homepage_section_controller.rb', line 28

def edit
  homepage_section_id = params[:id]
  @homepage_section = SpreeCmCommissioner::HomepageSection.find(homepage_section_id)
  @homepage_section_relatables = SpreeCmCommissioner::HomepageSectionRelatable.where(homepage_section: @homepage_section)
end

#location_after_save ⇒ Object



34
35
36
37
38
39
40
# File 'app/controllers/spree/admin/homepage_section_controller.rb', line 34

def location_after_save
  if @object.homepage_section_relatables_count.positive?
    collection_url
  else
    edit_admin_homepage_feed_homepage_section_url(@object)
  end
end

#model_class ⇒ Object



10
11
12
# File 'app/controllers/spree/admin/homepage_section_controller.rb', line 10

def model_class
  SpreeCmCommissioner::HomepageSection
end

#object_name ⇒ Object



14
15
16
# File 'app/controllers/spree/admin/homepage_section_controller.rb', line 14

def object_name
  'spree_cm_commissioner_homepage_section'
end