Class: SensorsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sensors_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_not_found_response

Instance Method Details

#createObject


15
16
17
18
19
20
21
22
# File 'app/controllers/sensors_controller.rb', line 15

def create 
  sensor = Sensor.new(sensor_params)
  if sensor.save
    render json: { status: 'SUCCESS', message: 'Saved new Sensor', data: sensor }, status: :ok
  else 
    render json: { status: 'ERROR', message: 'Sensor not saved', data: sensor.errors }, status: :unprocessable_entity
  end
end

#destroyObject


30
31
32
33
34
# File 'app/controllers/sensors_controller.rb', line 30

def destroy
  sensor = Sensor.find(params[:id])
  sensor.destroy
  render json: { status: 'SUCCESS', message: 'Sensor delete', data: sensor }, status: :ok
end

#indexObject


5
6
7
8
# File 'app/controllers/sensors_controller.rb', line 5

def index
  sensors = Sensor.all
  render json: { status: 'SUCCESS', message: 'Current sensors available', data: sensors }, status: :ok
end

#showObject


10
11
12
13
# File 'app/controllers/sensors_controller.rb', line 10

def show
  sensor = Sensor.find(params[:id])
  render json: { status: 'SUCCESS', message: 'Sensor of requested Id', data: sensor }, status: :ok
end

#updateObject


24
25
26
27
28
# File 'app/controllers/sensors_controller.rb', line 24

def update
  sensor = Sensor.find(params[:id])
  sensor.update_attributes(sensor_params)
  render json: { status: 'SUCCESS', message: 'Sensor updated', data: sensor }, status: :ok
end