Class: Upmin::ModelsController

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

Instance Method Summary collapse

Instance Method Details

#actionObject



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

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

#dashboardObject



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

def dashboard
end

#searchObject



46
47
48
49
# File 'app/controllers/upmin/models_controller.rb', line 46

def search
  @q = @klass.ransack(params[:q])
  @results = Upmin::Paginator.paginate(@q.result(distinct: true), @page, 30)
end

#showObject

GET /:model_name/:id



17
18
# File 'app/controllers/upmin/models_controller.rb', line 17

def show
end

#updateObject

PUT /:model_name/:id



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

def update
  instance = @model.instance
  updates = params[@klass.name.underscore]
  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] and not value.blank?
      value = transform(transforms, key, value)
    end

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

  if instance.save
    flash[:notice] = "#{@klass.humanized_name(:singular)} updated successfully."
    redirect_to(upmin_model_path(@model.path_hash))
  else
    flash.now[:alert] = "#{@klass.humanized_name(:singular)} was NOT updated."
    render(:show)
  end
end