Class: Spree::Api::V1::TaxonomiesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/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

Methods included from ControllerSetup

included

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/api/v1/taxonomies_controller.rb', line 16

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

#destroyObject



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

def destroy
  authorize! :delete, Taxonomy
  taxonomy.destroy
  render :text => nil, :status => 204
end

#indexObject



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

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

#showObject



12
13
14
# File 'app/controllers/spree/api/v1/taxonomies_controller.rb', line 12

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

#updateObject



26
27
28
29
30
31
32
33
# File 'app/controllers/spree/api/v1/taxonomies_controller.rb', line 26

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