scube-server/app/controllers/tracks_controller.rb
Thibault Jouan 5e1757aff9 Improve tracks CRUD
* Add index, edit and update action;
* Add _form partial;
* Add link to tracks/index in nav;
* Refactor specs.
2015-05-01 12:09:29 +00:00

45 lines
638 B
Ruby

class TracksController < ApplicationController
def index
@tracks = Track.all
end
def show
@track = Track.find(params[:id])
end
def new
@track = Track.new
end
def edit
@track = Track.find(params[:id])
end
def create
@track = Track.new(track_params)
if @track.save
redirect_to @track
else
render :new
end
end
def update
@track = Track.find(params[:id])
if @track.update_attributes track_params
redirect_to action: :index
else
render :edit
end
end
private
def track_params
params.require(:track).permit %i[name file]
end
end