Implement API sounds/create
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user