Class: Admin::EventRulesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::EventRulesController
- Defined in:
- app/controllers/admin/event_rules_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
GET /admin/event_rules —————————————————————————-.
-
#update ⇒ Object
PUT /admin/event_rules —————————————————————————-.
Instance Method Details
#index ⇒ Object
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 |
#update ⇒ Object
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 |