Class: Spree::Api::TaxonomiesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/taxonomies_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/spree/api/taxonomies_controller.rb', line 23

def create
  authorize! :create, Taxonomy
  @taxonomy = Taxonomy.new(params[:taxonomy])
  if @taxonomy.save
    respond_with(@taxonomy, :status => 201, :default_template => :show)
  else
    invalid_resource!(@taxonomy)
  end
end

#destroyObject



42
43
44
45
46
# File 'app/controllers/spree/api/taxonomies_controller.rb', line 42

def destroy
  authorize! :delete, Taxonomy
  taxonomy.destroy
  respond_with(taxonomy, :status => 204)
end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/spree/api/taxonomies_controller.rb', line 6

def index
  @taxonomies = Taxonomy.order('name').includes(:root => :children).
                ransack(params[:q]).result.
                page(params[:page]).per(params[:per_page])
  respond_with(@taxonomies)
end

#jstreeObject

Because JSTree wants parameters in a slightly different format



19
20
21
# File 'app/controllers/spree/api/taxonomies_controller.rb', line 19

def jstree
  show
end

#showObject



13
14
15
16
# File 'app/controllers/spree/api/taxonomies_controller.rb', line 13

def show
  @taxonomy = Taxonomy.find(params[:id])
  respond_with(@taxonomy)
end

#updateObject



33
34
35
36
37
38
39
40
# File 'app/controllers/spree/api/taxonomies_controller.rb', line 33

def update
  authorize! :update, Taxonomy
  if taxonomy.update_attributes(params[:taxonomy])
    respond_with(taxonomy, :status => 200, :default_template => :show)
  else
    invalid_resource!(taxonomy)
  end
end