Commit 0401676c86025ea3f6f944d13631bdb380857d25

Authored by Fellipe Souto Sampaio
Committed by Rafael Manzo
1 parent 536a0ac7

Edit and update feature for mezuro range

Pending unit and acceptance tests

signed-off-by: Renan Fichberg <rfichberg@gmail.com>
app/controllers/mezuro_ranges_controller.rb
... ... @@ -2,8 +2,9 @@ include OwnershipAuthentication
2 2  
3 3 class MezuroRangesController < ApplicationController
4 4 before_action :authenticate_user!, except: [:show]
5   - before_action :metric_configuration_owner?, only: [:new, :create, :destroy]
6   - before_action :get_url_params, only: [:create, :destroy]
  5 + before_action :metric_configuration_owner?, only: [:new, :create, :destroy, :update]
  6 + before_action :get_url_params, only: [:update, :create, :destroy]
  7 + before_action :set_mezuro_range, only: [:edit, :update]
7 8  
8 9 def new
9 10 @mezuro_range = MezuroRange.new
... ... @@ -28,10 +29,22 @@ class MezuroRangesController &lt; ApplicationController
28 29 end
29 30 end
30 31  
31   - def update
  32 + def edit
  33 + @mezuro_range_id = params[:mezuro_range_id]
  34 + before_form
32 35 end
33 36  
34   - def edit
  37 + def update
  38 + respond_to do |format|
  39 + @mezuro_range.metric_configuration_id = @metric_configuration_id
  40 + if @mezuro_range.update(mezuro_range_params)
  41 + format.html { redirect_to mezuro_configuration_metric_configuration_path(
  42 + @mezuro_configuration_id, @metric_configuration_id), notice: 'The range was successfully edited.' }
  43 + format.json { head :no_content }
  44 + else
  45 + failed_action(format, 'edit')
  46 + end
  47 + end
35 48 end
36 49  
37 50 private
... ... @@ -66,4 +79,8 @@ class MezuroRangesController &lt; ApplicationController
66 79 @metric_configuration_id = params[:metric_configuration_id].to_i
67 80 end
68 81  
  82 +
  83 + def set_mezuro_range
  84 + @mezuro_range = MezuroRange.find(params[:id].to_i)
  85 + end
69 86 end
... ...
app/views/metric_configurations/_ranges.html.erb
... ... @@ -4,7 +4,9 @@
4 4 <td><%= mezuro_range.end %></td>
5 5 <td>
6 6 <% if mezuro_configuration_owner? @metric_configuration.configuration_id %>
7   - <%= link_to 'Destroy Range', mezuro_configuration_metric_configuration_mezuro_range_path(@metric_configuration.configuration_id,
  7 + <%= link_to 'Edit', edit_mezuro_configuration_metric_configuration_mezuro_range_path(
  8 + @metric_configuration.configuration_id, @metric_configuration.id, mezuro_range.id), class: 'btn btn-info' %>
  9 + <%= link_to 'Destroy', mezuro_configuration_metric_configuration_mezuro_range_path(@metric_configuration.configuration_id,
8 10 @metric_configuration.id, mezuro_range.id), method: :delete, data: { confirm: 'Are you sure that you want to destroy this range?' },
9 11 class: 'btn btn-danger' %>
10 12 <% end %>
... ...
app/views/mezuro_ranges/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<h1>Edit Range</h1>
  2 +
  3 +<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_range_update_url(
  4 + @mezuro_configuration_id, @metric_configuration_id, @mezuro_range.id), method: :put) do |f| %>
  5 + <%= render partial: 'form', locals: {f: f} %>
  6 +<% end %>
0 7 \ No newline at end of file
... ...
app/views/mezuro_ranges/new.html.erb
1 1 <h1>New Range</h1>
2 2  
3   -<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_ranges_path(@mezuro_configuration_id, @metric_configuration_id)) do |f| %>
  3 +<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_ranges_path(
  4 + @mezuro_configuration_id, @metric_configuration_id)) do |f| %>
4 5 <%= render partial: 'form', locals: {f: f} %>
5 6 <% end %>
6 7 \ No newline at end of file
... ...