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