Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created August 1, 2018 16:42
Show Gist options
  • Save leemcalilly/f001f3a7e8e38444087641de78027720 to your computer and use it in GitHub Desktop.
Save leemcalilly/f001f3a7e8e38444087641de78027720 to your computer and use it in GitHub Desktop.
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