Class: Upmin::ModelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/upmin/models_controller.rb

Instance Method Summary collapse

Instance Method Details

#actionObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/upmin/models_controller.rb', line 53

def action
  # begin
  puts "arguments is: #{@arguments.inspect}"
    response = @model.perform_action(@instance, @method, @arguments)
    flash[:notice] = "Action successfully performed with a response of: #{response}"
    redirect_to(upmin_model_path(model_name: params[:model_name], id: params[:id]))
  # rescue Exception => e
  #   flash.now[:alert] = "Action failed with the error message: #{e.message}"
  #   render(:show)
  # end
end

#dashboardObject



10
11
# File 'app/controllers/upmin/models_controller.rb', line 10

def dashboard
end

#searchObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/upmin/models_controller.rb', line 43

def search
  # if @model.methods.include?(:ransack)
  puts params[:q]
  @q = @model.ransack(params[:q])
  # else
  #   @q = @model.search(params[:q])
  # end
  @results = @q.result(distinct: true)
end

#showObject

GET /:model_name/:id



14
15
# File 'app/controllers/upmin/models_controller.rb', line 14

def show
end

#updateObject

PUT /:model_name/:id



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/upmin/models_controller.rb', line 18

def update
  form_name = @model.form_name
  updates = params[form_name]

  transforms = updates.delete(:transforms) || {}
  updates.each do |key, value|
    # TODO(jon): Figure out a better way to do transforms.
    #   This could cause issues and is exploitable, but it
    #   should be fine for now since this is only on admin pages
    if transforms[key]
      value = transform(transforms, key, value)
    end

    @instance.send("#{key}=", value)
  end

  if @instance.save
    flash[:notice] = "#{params[:model_name]} updated successfully."
    redirect_to(upmin_model_path(model_name: @model.to_s, id: @instance.id))
  else
    flash.now[:alert] = "#{params[:model_name]} was NOT updated."
    render(:show)
  end
end