Refactor controllers
This commit is contained in:
parent
6001cd2e79
commit
8b226998a4
@ -1,11 +1,12 @@
|
|||||||
module API
|
module API
|
||||||
class PlaylistsController < ApplicationController
|
class PlaylistsController < ApplicationController
|
||||||
|
before_action :set_playlist, only: :show
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
@playlists = Playlist.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@playlist = Playlist.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@ -16,6 +17,10 @@ module API
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_playlist
|
||||||
|
@playlist = Playlist.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def playlist_params
|
def playlist_params
|
||||||
params.require(:playlist).permit :name
|
params.require(:playlist).permit :name
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
module API
|
module API
|
||||||
class SoundsController < ApplicationController
|
class SoundsController < ApplicationController
|
||||||
# FIXME: add some tests!
|
before_action :set_sound, only: :show
|
||||||
|
|
||||||
def show
|
def show
|
||||||
sound = Sound.find(params[:id])
|
|
||||||
send_file sound.path, type: sound.mime_type
|
send_file sound.path, type: sound.mime_type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_sound
|
||||||
|
@sound = Sound.find(params[:id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
module API
|
module API
|
||||||
class TracksController < ApplicationController
|
class TracksController < ApplicationController
|
||||||
|
before_action :set_track, only: :show
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tracks = Track.all
|
@tracks = Track.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_track
|
||||||
@track = Track.find(params[:id])
|
@track = Track.find(params[:id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
class PlaylistsController < ApplicationController
|
class PlaylistsController < ApplicationController
|
||||||
|
before_filter :set_playlist, only: %i[edit update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@playlists = Playlist.all
|
@playlists = Playlist.all
|
||||||
end
|
end
|
||||||
@ -11,29 +13,30 @@ class PlaylistsController < ApplicationController
|
|||||||
@playlist = current_user.playlists.build playlist_params
|
@playlist = current_user.playlists.build playlist_params
|
||||||
|
|
||||||
if @playlist.save
|
if @playlist.save
|
||||||
redirect_to action: 'index'
|
redirect_to action: :index
|
||||||
else
|
else
|
||||||
render action: 'new'
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@playlist = Playlist.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@playlist = Playlist.find(params[:id])
|
|
||||||
|
|
||||||
if @playlist.update_attributes playlist_params
|
if @playlist.update_attributes playlist_params
|
||||||
redirect_to action: 'index'
|
redirect_to action: :index
|
||||||
else
|
else
|
||||||
render action: 'edit'
|
render :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_playlist
|
||||||
|
@playlist = Playlist.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def playlist_params
|
def playlist_params
|
||||||
params.require(:playlist).permit :name
|
params.require(:playlist).permit :name
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ class SessionsController < ApplicationController
|
|||||||
self.current_user = user
|
self.current_user = user
|
||||||
redirect_to :root
|
redirect_to :root
|
||||||
else
|
else
|
||||||
render 'new'
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
class SoundsController < ApplicationController
|
class SoundsController < ApplicationController
|
||||||
|
before_filter :set_sound, only: :show
|
||||||
|
|
||||||
def show
|
def show
|
||||||
sound = Sound.find(params[:id])
|
send_file @sound.path, type: @sound.mime_type
|
||||||
send_file sound.path, type: sound.mime_type
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_sound
|
||||||
|
@sound = Sound.find(params[:id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
class TracksController < ApplicationController
|
class TracksController < ApplicationController
|
||||||
|
before_filter :set_track, only: %i[show edit update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tracks = Track.all
|
@tracks = Track.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@track = Track.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@ -12,7 +13,6 @@ class TracksController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@track = Track.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@ -26,8 +26,6 @@ class TracksController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@track = Track.find(params[:id])
|
|
||||||
|
|
||||||
if @track.update_attributes track_params
|
if @track.update_attributes track_params
|
||||||
redirect_to action: :index
|
redirect_to action: :index
|
||||||
else
|
else
|
||||||
@ -38,6 +36,10 @@ class TracksController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_track
|
||||||
|
@track = Track.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def track_params
|
def track_params
|
||||||
params.require(:track).permit %i[name file]
|
params.require(:track).permit %i[name file]
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,7 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
|
Loading…
x
Reference in New Issue
Block a user