Class: Spree::Admin::TaxonsController
- Inherits:
-
BaseController
- Object
- BaseController
- BaseController
- Spree::Admin::TaxonsController
- Defined in:
- app/controllers/spree/admin/taxons_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/spree/admin/taxons_controller.rb', line 21 def create @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] = Spree.t('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
67 68 69 70 71 |
# File 'app/controllers/spree/admin/taxons_controller.rb', line 67 def destroy @taxon = Taxon.find(params[:id]) @taxon.destroy respond_with(@taxon) { |format| format.json { render :json => '' } } end |
#edit ⇒ Object
35 36 37 |
# File 'app/controllers/spree/admin/taxons_controller.rb', line 35 def edit @permalink_part = @taxon.permalink.split("/").last end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/spree/admin/taxons_controller.rb', line 9 def index end |
#search ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/controllers/spree/admin/taxons_controller.rb', line 13 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
39 40 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 |
# File 'app/controllers/spree/admin/taxons_controller.rb', line 39 def update 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 if @taxon.update_attributes(taxon_params) flash[:success] = (@taxon, :successfully_updated) end #rename child taxons rename_child_taxons if @update_children respond_with(@taxon) do |format| format.html {redirect_to edit_admin_taxonomy_url(@taxonomy) } format.json {render :json => @taxon.to_json } end end |