Class: Georgia::WidgetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/georgia/widgets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #current_locale

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/georgia/widgets_controller.rb', line 16

def create
  @widget = Widget.new(widget_params)
  authorize @widget

  if @widget.save
    respond_to do |format|
      format.html { redirect_to widgets_url, notice: "Widget was successfully updated." }
      format.js { render layout: false }
    end
  else
    respond_to do |format|
      format.html { redirect_to widgets_url, alert: "Oups. Something went wrong." }
      format.js { render layout: false }
    end
  end

end

#destroyObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/georgia/widgets_controller.rb', line 51

def destroy
  @widget = Widget.find(params[:id])
  authorize @widget

  if @widget.destroy
    respond_to do |format|
      format.html { redirect_to widgets_url, notice: "Widget was successfully deleted." }
      format.js { head :ok }
    end
  else
    respond_to do |format|
      format.html { redirect_to widgets_url, alert: "Oups. Something went wrong." }
      format.js { head :internal_server_error }
    end
  end
end

#editObject



11
12
13
14
# File 'app/controllers/georgia/widgets_controller.rb', line 11

def edit
  @widget = Widget.find(params[:id])
  authorize @widget
end

#indexObject



4
5
6
7
8
9
# File 'app/controllers/georgia/widgets_controller.rb', line 4

def index
  authorize Widget
  @widgets = Widget.order(:created_at).page(params[:page]).in_groups_of(4, false)
  @widget = Widget.new
  @widget.contents.build(locale: current_locale)
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/georgia/widgets_controller.rb', line 34

def update
  @widget = Widget.find(params[:id])
  authorize @widget

  if @widget.update(widget_params)
    respond_to do |format|
      format.html { redirect_to widgets_url, notice: "Widget was successfully updated." }
      format.js { head :ok }
    end
  else
    respond_to do |format|
      format.html { render :index, alert: "Oups. Something went wrong." }
      format.js { head :internal_server_error }
    end
  end
end