Class: Prosperity::GraphsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Prosperity::GraphsController
- Defined in:
- app/controllers/prosperity/graphs_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/prosperity/graphs_controller.rb', line 60 def create @graph = Graph.new [:title, :period, :graph_type].each do |attr| @graph.public_send("#{attr}=", graph_params[attr]) end if @graph.save redirect_to edit_graph_path(@graph) else set_error(@graph) render action: :new end end |
#edit ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/controllers/prosperity/graphs_controller.rb', line 10 def edit @metrics = MetricFinder.all.map(&:new) @options = @metrics.inject({}) do |h, metric| h[metric.id] = metric..keys h end @graph.graph_lines.build end |
#new ⇒ Object
6 7 8 |
# File 'app/controllers/prosperity/graphs_controller.rb', line 6 def new @graph = Graph.new end |
#show ⇒ Object
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 48 49 50 51 |
# File 'app/controllers/prosperity/graphs_controller.rb', line 19 def show respond_to do |format| format.json do get_graph render json: { title: @graph.title, graph_type: @graph.graph_type, extractors: @graph.graph_lines.map do |line| { key: line.extractor, url: data_metric_path(id: line.metric, extractor: line.extractor, option: line.option, period: @graph.period, start_time: start_time, end_time: end_time), } end } end format.html { begin get_graph rescue ActiveRecord::RecordNotFound @graph = nil render layout: 'prosperity/embedabble', status: :not_found return end render layout: 'prosperity/embedabble' } end end |
#update ⇒ Object
53 54 55 56 57 58 |
# File 'app/controllers/prosperity/graphs_controller.rb', line 53 def update unless @graph.update_attributes(graph_params) set_error(@graph) end redirect_to action: :edit end |