Class: BandsController

Inherits:
ApplicationController show all
Defined in:
lib/scaffold/app/controllers/bands_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



19
20
21
22
23
24
25
26
27
28
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 19

def create
  @band = Band.new(band_params)

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

#destroyObject



45
46
47
48
49
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 45

def destroy
  @band = Band.find(params[:id])
  @band.destroy
  redirect_to bands_url
end

#editObject



30
31
32
33
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 30

def edit
  @band = Band.find(params[:id])
  render :edit
end

#indexObject



4
5
6
7
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 4

def index
  @bands = Band.all
  render :index
end

#jsonObject



51
52
53
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 51

def json
  @bands = Band.all
end

#newObject



14
15
16
17
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 14

def new
  @band = Band.new
  render :new
end

#showObject



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

def show
  @band = Band.find(params[:id])
  render :show
end

#updateObject



35
36
37
38
39
40
41
42
43
# File 'lib/scaffold/app/controllers/bands_controller.rb', line 35

def update
  @band = Band.find(params[:id])
  if @band.update_attributes(band_params)
    redirect_to band_url(@band)
  else
    flash.now[:errors] = @band.errors.full_messages
    render :edit
  end
end