Class: Realiser::Web::SettingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/realiser/web/settings_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/realiser/web/settings_controller.rb', line 39

def create
  @setting = Realiser::Setting.new(form_params)
  if @setting.invalid?
    flash.now[:danger] = @setting.errors.full_messages.join(', ')
    return render :new
  end
  @setting.save!
  flash[:success] = 'Succesfully created a new setting'
  redirect_to root_path
end

#destroyObject

rubocop:enable Style/RedundantArgument



32
33
34
35
36
37
# File 'app/controllers/realiser/web/settings_controller.rb', line 32

def destroy
  setting = Realiser::Setting.find_by(id: params[:id])
  setting.destroy!
  flash[:success] = 'Successfully deleted the setting'
  redirect_to root_path
end

#editObject



16
17
18
# File 'app/controllers/realiser/web/settings_controller.rb', line 16

def edit
  @setting = Realiser::Setting.find_by(id: params[:id])
end

#indexObject



4
5
6
# File 'app/controllers/realiser/web/settings_controller.rb', line 4

def index
  @settings = Realiser::Setting.all
end

#newObject



8
9
10
# File 'app/controllers/realiser/web/settings_controller.rb', line 8

def new
  @setting = Realiser::Setting.new
end

#showObject



12
13
14
# File 'app/controllers/realiser/web/settings_controller.rb', line 12

def show
  @setting = Realiser::Setting.find_by(id: params[:id])
end

#updateObject

rubocop:disable Style/RedundantArgument



21
22
23
24
25
26
27
28
29
# File 'app/controllers/realiser/web/settings_controller.rb', line 21

def update
  setting = Realiser::Setting.find_by(id: params[:id])
  if setting.update(form_params)
    flash[:success] = 'Successfully to update the setting'
    return redirect_to web_setting_path(setting)
  end
  flash.now[:danger] = setting.errors.full_messages.join('')
  render :edit
end