Class: OutroRails::ChordCharts::VoicingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/outro_rails/chord_charts/voicings_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/outro_rails/chord_charts/voicings_controller.rb', line 16

def create
  voicing = @chord.voicings.find(params.require(:chord_voicing_id))
  selection = @chord_chart.voicings.find_or_initialize_by(
    chord: @chord, instrument: @instrument, bass: @bass.to_s
  )
  selection.chord_voicing = voicing

  if selection.save
    redirect_to after_change_path,
                notice: "Now showing #{voicing.symbol} " \
                  "for #{@chord.symbol}."
  elsif return_to_path
    redirect_to return_to_path,
                alert: selection.errors.full_messages.to_sentence
  else
    set_voicings
    flash.now[:alert] = selection.errors.full_messages.to_sentence
    render :index, status: :unprocessable_entity
  end
end

#destroyObject



37
38
39
40
41
42
# File 'app/controllers/outro_rails/chord_charts/voicings_controller.rb', line 37

def destroy
  @chord_chart.voicings.find(params[:id]).destroy

  redirect_to after_change_path,
              notice: "Reverted to the default voicing."
end

#indexObject



12
13
14
# File 'app/controllers/outro_rails/chord_charts/voicings_controller.rb', line 12

def index
  set_voicings
end