Class: GeoLabels::RatingsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#main

Instance Method Details

#getObject

Still has no application



9
10
11
# File 'app/controllers/geo_labels/ratings_controller.rb', line 9

def get
  render plain: 'TODO app/controllers/geo_labels/ratings_controller.rb'
end

#setObject

PUT /geo-labels/ratings/set?record=GeoLabels::Contact&record_id=3&topic=food&value=7



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/geo_labels/ratings_controller.rb', line 14

def set
  model = params[:record].safe_constantize
  return render plain: '', status: :unprocessable_entity unless model&.include?(GeoLabels::RatingsSupport) # 422
  return render plain: '', status: :unprocessable_entity unless model.rating_topics.include? params[:topic].to_sym

  record = model.find(params[:record_id])
  #TODO: add more sophisticated safeguard
  record.rating[params[:topic]] = params[:value]

  if record.save
    render plain: ''
  else
    render plain: '', status: :unprocessable_entity
  end
end