Class: AlbumsController

Inherits:
ApplicationController show all
Defined in:
lib/scaffold/app/controllers/albums_controller.rb

Constant Summary

Constants included from ControllerCallbacks

ControllerCallbacks::METHODS

Instance Attribute Summary

Attributes inherited from ControllerBase

#params, #req, #res

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #ensure_login, #ensure_logout, #logged_in?, #login, #logout

Methods inherited from ControllerBase

#form_authenticity_token, #initialize, #invoke_action, #link_to, protect_from_forgery, #root_url

Methods included from ControllerCallbacks

#before_action

Constructor Details

This class inherits a constructor from ControllerBase

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/scaffold/app/controllers/albums_controller.rb', line 14

def create
  @album = Album.new(album_params)

  if @album.save
    redirect_to album_url(@album)
  else
    @band = @album.band
    flash.now[:errors] = @album.errors
    render :new
  end
end

#destroyObject



42
43
44
45
46
# File 'lib/scaffold/app/controllers/albums_controller.rb', line 42

def destroy
  @album = Album.find(params[:id])
  @album.destroy
  redirect_to band_url(@album.band_id)
end

#editObject



26
27
28
29
# File 'lib/scaffold/app/controllers/albums_controller.rb', line 26

def edit
  @album = Album.find(params[:id])
  render :edit
end

#newObject



8
9
10
11
12
# File 'lib/scaffold/app/controllers/albums_controller.rb', line 8

def new
  @band = Band.find(params[:band_id])
  @album = Album.new(band_id: params[:band_id])
  render :new
end

#showObject



3
4
5
6
# File 'lib/scaffold/app/controllers/albums_controller.rb', line 3

def show
  @album = Album.find(params[:id])
  render :show
end

#updateObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/scaffold/app/controllers/albums_controller.rb', line 31

def update
  @album = Album.find(params[:id])

  if @album.update_attributes(album_params)
    redirect_to album_url(@album)
  else
    flash.now[:errors] = @album.errors
    render :edit
  end
end