Class: Admin::EventRulesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/event_rules_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /admin/event_rules




7
8
9
10
11
12
13
14
# File 'app/controllers/admin/event_rules_controller.rb', line 7

def index
  @event_rules = EventRule.all
  @event_rules << EventRule.new if @event_rules.empty?

  respond_to do |format|
    format.html # index.html.haml
  end
end

#updateObject

PUT /admin/event_rules




18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/admin/event_rules_controller.rb', line 18

def update
  # Create rules without ids,
  # destroy rules with '_destroy' param,
  # update rules with ids
  @event_rules = []
  params[:event_rules].each do |index, data|
    if data["id"].blank?
      @event_rules << EventRule.create(data)
    else
      if rule = EventRule.find_by_id(data["id"])
        if data["_destroy"]
          rule.destroy
        else
          rule.update_attributes data
          @event_rules << rule
        end
      end
    end
  end

  if @event_rules.all?(&:valid?)
    flash[:notice] = "All rules were saved successfully."
  else
    flash[:error] = render_to_string(:partial => "errors").html_safe
  end

  respond_to do |format|
    format.html { render "index" }
  end
end