Class: Spree::Admin::TaxonsController

Inherits:
ResourceController show all
Includes:
Translatable
Defined in:
app/controllers/spree/admin/taxons_controller.rb

Instance Method Summary collapse

Methods included from Translatable

#edit_translations

Methods inherited from ResourceController

belongs_to, #create, #destroy, #edit, #new, #update_positions

Instance Method Details

#edit_admin_taxon_path(taxon) ⇒ Object

This method is added here to allow edit_polymorphic_path to work



61
62
63
# File 'app/controllers/spree/admin/taxons_controller.rb', line 61

def edit_admin_taxon_path(taxon)
  spree.edit_admin_taxonomy_taxon_path(taxon.taxonomy, taxon.id)
end

#index ⇒ Object



11
# File 'app/controllers/spree/admin/taxons_controller.rb', line 11

def index; end

#remove_icon ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/controllers/spree/admin/taxons_controller.rb', line 50

def remove_icon
  if @taxon.icon.destroy
    flash[:success] = Spree.t('notice_messages.icon_removed')
    redirect_to spree.edit_admin_taxonomy_taxon_url(@taxonomy.id, @taxon.id)
  else
    flash[:error] = Spree.t('errors.messages.cannot_remove_icon')
    render :edit, status: :unprocessable_entity
  end
end

#update ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/spree/admin/taxons_controller.rb', line 13

def update
  successful = @taxon.transaction do
    parent_id = params[:taxon][:parent_id]
    set_position
    set_parent(parent_id)

    @taxon.save!

    # regenerate permalink
    regenerate_permalink if parent_id

    set_permalink_params

    # check if we need to rename child taxons if parent name or permalink changes
    @update_children = true if params[:taxon][:name] != @taxon.name || params[:taxon][:permalink] != @taxon.permalink

    @taxon.create_icon(attachment: taxon_params[:icon]) if taxon_params[:icon]
    @taxon.update(taxon_params.except(:icon))
  end
  if successful
    flash[:success] = flash_message_for(@taxon, :successfully_updated)

    # rename child taxons
    rename_child_taxons if @update_children

    respond_with(@taxon) do |format|
      format.html { redirect_to spree.edit_admin_taxonomy_taxon_path(@taxonomy.id, @taxon.id) }
      format.json { render json: @taxon.to_json }
    end
  else
    respond_with(@taxon) do |format|
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @taxon.errors.full_messages.to_sentence, status: :unprocessable_entity }
    end
  end
end