Class: Spree::Api::PropertiesController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/spree/api/properties_controller.rb', line 28

def create
  authorize! :create, Property
  @property = Spree::Property.new(property_params)
  if @property.save
    respond_with(@property, status: 201, default_template: :show)
  else
    invalid_resource!(@property)
  end
end

#destroyObject



48
49
50
51
52
53
54
55
56
# File 'app/controllers/spree/api/properties_controller.rb', line 48

def destroy
  if @property
    authorize! :destroy, @property
    @property.destroy
    respond_with(@property, status: 204)
  else
    invalid_resource!(@property)
  end
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/api/properties_controller.rb', line 7

def index
  @properties = Spree::Property.accessible_by(current_ability, :read)

  if params[:ids]
    ids = params[:ids].split(",").flatten
    @properties = @properties.where(:id => ids)
  else
    @properties = @properties.ransack(params[:q]).result
  end

  @properties = @properties.page(params[:page]).per(params[:per_page])
  respond_with(@properties)
end

#newObject



25
26
# File 'app/controllers/spree/api/properties_controller.rb', line 25

def new
end

#showObject



21
22
23
# File 'app/controllers/spree/api/properties_controller.rb', line 21

def show
  respond_with(@property)
end

#updateObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/spree/api/properties_controller.rb', line 38

def update
  if @property
    authorize! :update, @property
    @property.update_attributes(property_params)
    respond_with(@property, status: 200, default_template: :show)
  else
    invalid_resource!(@property)
  end
end