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