app/controllers/prosperity/graphs_controller.rb in prosperity-0.0.6 vs app/controllers/prosperity/graphs_controller.rb in prosperity-0.0.7

- old
+ new

@@ -15,24 +15,33 @@ end @graph.graph_lines.build end def show - render json: { - title: @graph.title, - 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), + respond_to do |format| + format.json do + 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 { + render layout: 'prosperity/embedabble' + } + end end def update unless @graph.update_attributes(graph_params) set_error(@graph) @@ -40,22 +49,22 @@ redirect_to action: :edit end def create @graph = Graph.new - [:title, :period].each do |attr| + [:title, :period, :graph_type].each do |attr| @graph.send("#{attr}=", graph_params[attr]) end if @graph.save redirect_to edit_graph_path(@graph) else set_error(@graph) render action: :new end end - + private def get_graph @graph = Graph.find(params[:id]) end @@ -63,10 +72,10 @@ def graph_params if strong_params? params.require(:graph). permit(Graph::ATTR_ACCESSIBLE + [:graph_lines_attributes => (GraphLine::ATTR_ACCESSIBLE + [:id])]) else - params.fetch(:graph, {}) + params.fetch(:graph, {}) end end end end