Class: Caboose::AbOptionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/ab_options_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_createObject

POST admin/ab-variants/:variant_id/options’



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/caboose/ab_options_controller.rb', line 13

def admin_create
  return unless user_is_allowed_to 'edit','ab_variants'
  
  resp = StdClass.new({
    'error' => nil,
    'redirect' => nil
  })
  
  opt = AbOption.create(
    :ab_variant_id => params[:variant_id],
    :text => params[:text]
  )      
  resp.redirect = "/admin/ab-variants/#{params[:variant_id]}"      
  render :json => resp
end

#admin_deleteObject

DELETE /admin/ab_options/:id



50
51
52
53
54
# File 'app/controllers/caboose/ab_options_controller.rb', line 50

def admin_delete
  return unless user_is_allowed_to 'delete', 'ab_variants'      
  AbOption.find(params[:id]).destroy                  
  render :json => true
end

#admin_indexObject

GET /admin/ab_variants/:variant_id/options



6
7
8
9
10
# File 'app/controllers/caboose/ab_options_controller.rb', line 6

def admin_index
  return unless user_is_allowed_to 'view', 'ab_variants'
  v = AbVariant.find(params[:variant_id])
  render :json => v.ab_options
end

#admin_updateObject

PUT /admin/ab_options/:id



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/caboose/ab_options_controller.rb', line 30

def admin_update
  return unless user_is_allowed_to 'edit', 'ab_variants'

  resp = StdClass.new
  opt = AbOption.find(params[:id])

  save = true
  params.each do |k,v|
    case k
      when 'value'
        opt.value = v
        break
    end
  end      

  resp.success = save && opt.save      
  render :json => resp
end