Class: ActsAsWarnable::WarningsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/acts_as_warnable/warnings_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



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

def index
  @warnings = Warning.all
  @warnings = @warnings.active if params[:active_only]

  if params.key?(:warnable_id) && params.key?(:warnable_type)
    @warnings = @warnings.where(warnable_id: params[:warnable_id], warnable_type: params[:warnable_type])

    @warnable = params[:warnable_type].constantize.find(params[:warnable_id])
    instance_variable_set('@'+params[:warnable_type].underscore, @warnable)

    warnables = params[:warnable_type].underscore.pluralize
    if lookup_context.exists?('warnings', warnables, false)
      render "#{warnables}/warnings"
    end
  end
end

#showObject



52
53
54
# File 'app/controllers/acts_as_warnable/warnings_controller.rb', line 52

def show
  render params[:render] if params.key?(:render)
end

#updateObject



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

def update
  was_dismissed = @warning.dismissed?
  if @warning.update_attributes(permitted_params[:warning])
    if !was_dismissed && @warning.dismissed?
      flash[:success] = "Warning dismissed"
    else
      flash[:success] = "Successfully updated warning"
    end
  else
    flash[:error] = "Failed to update warning: #{@warning.errors.full_messages.join(', ')}"
  end

  if params[:redirect_to]
    redirect_to params[:redirect_to]
  else
    redirect_to warnings_path
  end
end