Class: Cullender::RulesController

Inherits:
CullenderController show all
Includes:
Controllers::FilterLogic
Defined in:
app/controllers/cullender/rules_controller.rb

Instance Method Summary collapse

Methods included from Controllers::FilterLogic

#add_and_filter, #add_operator, #add_or_filter, #apply_filter_actions, #clean_field, #remove_and_filter

Methods inherited from CullenderController

#_prefixes, #cullender_mapping, #resource, #resource_class, #resource_name, #resource_params

Instance Method Details

#createObject

POST /rules



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/cullender/rules_controller.rb', line 24

def create
  flag = apply_filter_actions("triggers", params[:rule], params)
  @rule = Cullender::Rule.new(rule_params)
  respond_to do |format|
    if flag
        format.html {redirect_to send("new_#{resource_name}_rule_url".to_sym,params[:rule])}
        format.js { render "create"}
    else
      if @rule.save
        format.html {redirect_to send("#{resource_name}_rules_url".to_sym), notice: 'Rule was successfully created.'}
        format.js {redirect_to send("#{resource_name}_rules_url".to_sym), notice: 'Rule was successfully created.'}
      else
        format.html {render action: 'new'}
        format.js {render action: 'new'}
      end
    end
  end
end

#destroyObject

DELETE /rules/1



54
55
56
57
58
# File 'app/controllers/cullender/rules_controller.rb', line 54

def destroy
  @rule = Cullender::Rule.find(params[:id])
  @rule.destroy
  redirect_to send("#{resource_name}_rules_url".to_sym), notice: 'Rule was successfully destroyed.'
end

#indexObject

TODO should route without resource. ie not event/rules just /rules GET /rules



8
9
10
# File 'app/controllers/cullender/rules_controller.rb', line 8

def index
  @rules = Cullender::Rule.all
end

#newObject

GET /rules/new



19
20
21
# File 'app/controllers/cullender/rules_controller.rb', line 19

def new
  @rule = Cullender::Rule.new(name: params[:name])
end

#showObject

GET /rules/1



13
14
15
16
# File 'app/controllers/cullender/rules_controller.rb', line 13

def show
  @rule = Cullender::Rule.find(params[:id])
  params.deep_merge!({"rule" => {"triggers" => @rule.triggers}})
end

#updateObject

PATCH/PUT /rules/1



44
45
46
47
48
49
50
51
# File 'app/controllers/cullender/rules_controller.rb', line 44

def update
  @rule = Cullender::Rule.find(params[:id])
  if !apply_filter_actions("triggers", params[:rule], params) && @rule.update_attributes(rule_params)
    redirect_to send("#{resource_name}_rules_url".to_sym), notice: 'Rule was successfully updated.'
  else
    render action: 'show'
  end
end