Skip to content

Instantly share code, notes, and snippets.

@austinklenk
Created May 23, 2018 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinklenk/67f0d4af4c15a79d6c8da5a2ef6247d9 to your computer and use it in GitHub Desktop.
Save austinklenk/67f0d4af4c15a79d6c8da5a2ef6247d9 to your computer and use it in GitHub Desktop.
def index
@albums = Album.all.with_attached_images
end
def show
authorize! :show, @album
@album = Album.friendly.find(params[:id])
end
def new
authorize! :new, @album
@gallery = Gallery.find(params[:gallery_id])
@album = @gallery.albums.build
end
def edit
authorize! :edit, @album
end
def create
authorize! :create, @album
@album = Album.new(album_params)
respond_to do |format|
if @album.save
format.html { redirect_to @album, notice: 'Album was successfully created.' }
else
format.html { render :new }
end
end
end
def update
authorize! :update, @album
respond_to do |format|
if @album.update(album_params)
format.html { redirect_to @album, notice: 'Album was successfully updated.' }
format.json { render :show, status: :ok, location: @album }
else
format.html { render :edit }
end
end
end
def destroy
authorize! :destroy, @album
@album.destroy
respond_to do |format|
format.html { redirect_to root_url, notice: 'Album was successfully destroyed.' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment