diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 454fc83..65e15bf 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -5,6 +5,7 @@ class QuantitiesController < ApplicationController def index @quantity = Quantity.new + @quantities = @project.quantities end def create @@ -13,6 +14,7 @@ class QuantitiesController < ApplicationController flash[:notice] = 'Created new quantity' redirect_to project_quantities_url(@project) else + @quantities = @project.quantities render :index end end diff --git a/app/helpers/quantities_helper.rb b/app/helpers/quantities_helper.rb index 6a4892c..fe34c7f 100644 --- a/app/helpers/quantities_helper.rb +++ b/app/helpers/quantities_helper.rb @@ -7,7 +7,7 @@ module QuantitiesHelper end def parent_options - options = nested_set_options(Quantity, @quantity) do |i| + options = nested_set_options(@quantities, @quantity) do |i| raw("#{' ' * i.level}#{i.name}") end options.unshift([t('.null_parent'), nil]) diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index 43c0666..a330a2e 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -23,7 +23,7 @@

<%= t ".heading" %>

-<% if Quantity.roots.any? %> +<% if @quantities.any? %> @@ -34,8 +34,7 @@ - <% Quantity.roots.each do |r| %> - <% Quantity.each_with_level(r.self_and_descendants) do |q, level| %> + <% Quantity.each_with_level(@quantities) do |q, level| %> 0 %>"> @@ -44,7 +43,6 @@ <% end %> - <% end %>
<%= q.name %><%= delete_link quantity_path(q), data: {} %>
<% else %>