Module: Api::Media
- Extended by:
- ActiveSupport::Concern
- Included in:
- ChallengesController, DatasetsController, NeedsController, ProgramsController, ProjectsController, SpacesController, WorkgroupsController
- Defined in:
- app/controllers/concerns/api/media.rb
Instance Method Summary collapse
-
#media_create ⇒ Object
POST /media.
-
#media_destroy ⇒ Object
DELETE /media/1.
-
#media_index ⇒ Object
GET /media.
-
#media_show ⇒ Object
GET /media/1.
-
#media_update ⇒ Object
PATCH/PUT /media/1.
- #media_upload ⇒ Object
Instance Method Details
#media_create ⇒ Object
POST /media
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/concerns/api/media.rb', line 25 def media_create @medium = Medium.new(medium_params) @medium.mediumable = @obj if @medium.save raise ApiExceptions::UnprocessableEntity.new(message: 'Missing item') if params[:item].nil? @medium.item.attach(params[:item]) raise ApiExceptions::UnprocessableEntity.new(message: 'Something went wrong') unless @medium.item.attached? @medium.item.filename = @medium.item.filename.to_s.sub('(', '-').sub(')', '-') unless @medium.item.save raise ApiExceptions::UnprocessableEntity.new(message: 'Something went wrong') end render json: @medium, status: :created else render json: @medium.errors, status: :unprocessable_entity end end |
#media_destroy ⇒ Object
DELETE /media/1
56 57 58 |
# File 'app/controllers/concerns/api/media.rb', line 56 def media_destroy @medium.destroy end |
#media_index ⇒ Object
GET /media
14 15 16 17 |
# File 'app/controllers/concerns/api/media.rb', line 14 def media_index @media = @obj.media render json: @media end |
#media_show ⇒ Object
GET /media/1
20 21 22 |
# File 'app/controllers/concerns/api/media.rb', line 20 def media_show render json: @medium end |
#media_update ⇒ Object
PATCH/PUT /media/1
47 48 49 50 51 52 53 |
# File 'app/controllers/concerns/api/media.rb', line 47 def media_update if @medium.update(medium_params) render json: @medium else render json: @medium.errors, status: :unprocessable_entity end end |
#media_upload ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/concerns/api/media.rb', line 60 def media_upload raise ApiExceptions::UnprocessableEntity.new(message: 'Missing item') if params[:item].nil? @medium.item.attach(params[:item]) raise ApiExceptions::UnprocessableEntity.new(message: 'Something went wrong') unless @medium.item.attached? @medium.item.filename = @medium.item.filename.to_s.sub('(', '-').sub(')', '-') unless @medium.item.save raise ApiExceptions::UnprocessableEntity.new(message: 'Something went wrong') end render json: @medium end |