Refactor controllers
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user