Class: Spree::Admin::TaxonsController
Instance Method Summary
collapse
#set_user_language_locale_key
Instance Method Details
#create ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/spree/admin/taxons_controller.rb', line 20
def create
@taxonomy = Spree::Taxonomy.find(params[:taxonomy_id])
@taxon = @taxonomy.taxons.build(params[:taxon])
if @taxon.save
respond_with(@taxon) do |format|
format.json { render json: @taxon.to_json }
end
else
flash[:error] = t('spree.errors.messages.could_not_create_taxon')
respond_with(@taxon) do |format|
format.html { redirect_to @taxonomy ? edit_admin_taxonomy_url(@taxonomy) : admin_taxonomies_url }
end
end
end
|
#destroy ⇒ Object
76
77
78
79
80
|
# File 'app/controllers/spree/admin/taxons_controller.rb', line 76
def destroy
@taxon = Spree::Taxon.find(params[:id])
@taxon.destroy
respond_with(@taxon) { |format| format.json { render json: '' } }
end
|
#edit ⇒ Object
35
36
37
38
39
|
# File 'app/controllers/spree/admin/taxons_controller.rb', line 35
def edit
@taxonomy = Spree::Taxonomy.find(params[:taxonomy_id])
@taxon = @taxonomy.taxons.find(params[:id])
@permalink_part = @taxon.permalink.split("/").last
end
|
#index ⇒ Object
9
10
|
# File 'app/controllers/spree/admin/taxons_controller.rb', line 9
def index
end
|
#search ⇒ Object
12
13
14
15
16
17
18
|
# File 'app/controllers/spree/admin/taxons_controller.rb', line 12
def search
if params[:ids]
@taxons = Spree::Taxon.where(id: params[:ids].split(','))
else
@taxons = Spree::Taxon.limit(20).ransack(name_cont: params[:q]).result
end
end
|
#update ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/spree/admin/taxons_controller.rb', line 41
def update
@taxonomy = Spree::Taxonomy.find(params[:taxonomy_id])
@taxon = @taxonomy.taxons.find(params[:id])
parent_id = params[:taxon][:parent_id]
new_position = params[:taxon][:position]
if parent_id
@taxon.parent = Spree::Taxon.find(parent_id.to_i)
end
if new_position
@taxon.child_index = new_position.to_i
end
if params[:permalink_part]
@taxon.permalink_part = params[:permalink_part].to_s
end
@taxon.assign_attributes(taxon_params)
if @taxon.save
flash[:success] = flash_message_for(@taxon, :successfully_updated)
end
respond_with(@taxon) do |format|
format.html do
if @taxon.valid?
redirect_to edit_admin_taxonomy_url(@taxonomy)
else
render :edit
end
end
end
end
|