Implement API sounds/create

This commit is contained in:
Thibault Jouan
2015-05-06 06:28:02 +00:00
parent b8d25dc918
commit 54ae036adc
3 changed files with 54 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
module API
class SoundsController < ApplicationController
skip_before_filter :json_filter!, only: :show
skip_before_filter :json_filter!, only: %i[show create]
before_action :set_sound, only: :show
@@ -8,6 +8,15 @@ module API
send_file @sound.path, type: @sound.mime_type
end
def create
@sound = Sound.new(sound_params)
if @sound.save
render :show, status: :created, location: api_sound_path(@sound)
else
render json: @sound.errors, status: :unprocessable_entity
end
end
private
@@ -17,5 +26,9 @@ module API
when /\A\h+\z/ then Sound.find_by_sha256!(params[:id])
end
end
def sound_params
params.require(:sound).permit :file
end
end
end