Created
August 1, 2018 16:42
-
-
Save leemcalilly/f001f3a7e8e38444087641de78027720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArtistsController < ApplicationController | |
before_action :set_artist, only: [:show, :edit, :update, :destroy] | |
skip_before_action :require_login, only: [:index, :show] | |
def index | |
@artists = Artist.all | |
end | |
def show | |
end | |
def new | |
@artist = Artist.new | |
authorize @artist | |
end | |
def edit | |
authorize @artist | |
end | |
def create | |
@artist = current_user.artists.build(artist_params) | |
authorize @artist | |
if @artist.save | |
flash[:success] = 'Artist was successfully created.' | |
redirect_to @artist | |
else | |
render :new | |
end | |
end | |
def update | |
authorize @artist | |
if @artist.update(artist_params) | |
flash[:success] = "Artist updated" | |
redirect_to @artist | |
else | |
render :edit | |
end | |
end | |
def destroy | |
authorize @artist | |
@artist.destroy | |
flash[:success] = "Artist deleted" | |
redirect_to artists_path | |
end | |
private | |
def set_artist | |
@artist = Artist.find(params[:id]) | |
end | |
def artist_params | |
params.require(:artist).permit(:name, :group) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment