diff --git a/app/controllers/mezuro_ranges_controller.rb b/app/controllers/mezuro_ranges_controller.rb index 22da4ff..a92f780 100644 --- a/app/controllers/mezuro_ranges_controller.rb +++ b/app/controllers/mezuro_ranges_controller.rb @@ -2,8 +2,9 @@ include OwnershipAuthentication class MezuroRangesController < ApplicationController before_action :authenticate_user!, except: [:show] - before_action :metric_configuration_owner?, only: [:new, :create, :destroy] - before_action :get_url_params, only: [:create, :destroy] + before_action :metric_configuration_owner?, only: [:new, :create, :destroy, :update] + before_action :get_url_params, only: [:update, :create, :destroy] + before_action :set_mezuro_range, only: [:edit, :update] def new @mezuro_range = MezuroRange.new @@ -28,10 +29,22 @@ class MezuroRangesController < ApplicationController end end - def update + def edit + @mezuro_range_id = params[:mezuro_range_id] + before_form end - def edit + def update + respond_to do |format| + @mezuro_range.metric_configuration_id = @metric_configuration_id + if @mezuro_range.update(mezuro_range_params) + format.html { redirect_to mezuro_configuration_metric_configuration_path( + @mezuro_configuration_id, @metric_configuration_id), notice: 'The range was successfully edited.' } + format.json { head :no_content } + else + failed_action(format, 'edit') + end + end end private @@ -66,4 +79,8 @@ class MezuroRangesController < ApplicationController @metric_configuration_id = params[:metric_configuration_id].to_i end + + def set_mezuro_range + @mezuro_range = MezuroRange.find(params[:id].to_i) + end end diff --git a/app/views/metric_configurations/_ranges.html.erb b/app/views/metric_configurations/_ranges.html.erb index 497a77c..52fb6f3 100644 --- a/app/views/metric_configurations/_ranges.html.erb +++ b/app/views/metric_configurations/_ranges.html.erb @@ -4,7 +4,9 @@ <%= mezuro_range.end %> <% if mezuro_configuration_owner? @metric_configuration.configuration_id %> - <%= link_to 'Destroy Range', mezuro_configuration_metric_configuration_mezuro_range_path(@metric_configuration.configuration_id, + <%= link_to 'Edit', edit_mezuro_configuration_metric_configuration_mezuro_range_path( + @metric_configuration.configuration_id, @metric_configuration.id, mezuro_range.id), class: 'btn btn-info' %> + <%= link_to 'Destroy', mezuro_configuration_metric_configuration_mezuro_range_path(@metric_configuration.configuration_id, @metric_configuration.id, mezuro_range.id), method: :delete, data: { confirm: 'Are you sure that you want to destroy this range?' }, class: 'btn btn-danger' %> <% end %> diff --git a/app/views/mezuro_ranges/edit.html.erb b/app/views/mezuro_ranges/edit.html.erb new file mode 100644 index 0000000..b26af48 --- /dev/null +++ b/app/views/mezuro_ranges/edit.html.erb @@ -0,0 +1,6 @@ +

Edit Range

+ +<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_range_update_url( + @mezuro_configuration_id, @metric_configuration_id, @mezuro_range.id), method: :put) do |f| %> + <%= render partial: 'form', locals: {f: f} %> +<% end %> \ No newline at end of file diff --git a/app/views/mezuro_ranges/new.html.erb b/app/views/mezuro_ranges/new.html.erb index 9b91b99..9fea332 100644 --- a/app/views/mezuro_ranges/new.html.erb +++ b/app/views/mezuro_ranges/new.html.erb @@ -1,5 +1,6 @@

New Range

-<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_ranges_path(@mezuro_configuration_id, @metric_configuration_id)) do |f| %> +<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_ranges_path( + @mezuro_configuration_id, @metric_configuration_id)) do |f| %> <%= render partial: 'form', locals: {f: f} %> <% end %> \ No newline at end of file -- libgit2 0.21.2