Module: Insights::API::Common::TaggingMethods
- Defined in:
- app/controllers/concerns/insights/api/common/tagging_methods.rb
Instance Method Summary collapse
Instance Method Details
#tag ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/concerns/insights/api/common/tagging_methods.rb', line 5 def tag primary_instance = primary_collection_model.find(request_path_parts["primary_collection_id"]) = parsed_body.collect do |i| begin tag = Tag.find_or_create_by!(Tag.parse(i["tag"])) primary_instance. << tag i rescue ActiveRecord::RecordNotUnique end end.compact # HTTP Not Modified return head(304, :location => "#{instance_link(primary_instance)}/tags") if .empty? # HTTP Created render :json => parsed_body, :status => 201, :location => "#{instance_link(primary_instance)}/tags" end |
#untag ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/concerns/insights/api/common/tagging_methods.rb', line 24 def untag primary_instance = primary_collection_model.find(request_path_parts["primary_collection_id"]) parsed_body.each do |i| tag = Tag.find_by(Tag.parse(i["tag"])) primary_instance..destroy(tag) if tag end # HTTP No Content head 204, :location => "#{instance_link(primary_instance)}/tags" end |