diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 6a38e20..7f4c166 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -361,6 +361,12 @@ table.items td:not(:first-child) { color: #909090; fill: #909090; } +table.items td.hint { + color: #909090; + font-style: italic; + font-size: 0.8rem; + padding: 1em; +} table.items svg { height: 1.2rem; vertical-align: middle; diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 02293a8..366e1b1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -44,4 +44,9 @@ class ApplicationController < ActionController::Base flash.alert = t("actioncontroller.exceptions.status.#{message_id}") redirect_to request.referer end + + def run_and_render(action) + send action + render action + end end diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index 6a085eb..f3ce508 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -5,7 +5,7 @@ class UnitsController < ApplicationController raise AccessForbidden unless current_user.at_least(:active) end before_action only: [:edit, :update, :destroy] do - raise ArgumentError unless current_user == @unit.user + raise ParameterInvalid unless current_user == @unit.user end def index @@ -20,7 +20,7 @@ class UnitsController < ApplicationController @unit = current_user.units.new(unit_params) if @unit.save flash[:notice] = t(".success") - @units = current_user.units + run_and_render :index else render :new end @@ -32,7 +32,7 @@ class UnitsController < ApplicationController def update if @unit.update(unit_params) flash[:notice] = t(".success") - redirect_to units_url + run_and_render :index else render :edit end @@ -42,7 +42,7 @@ class UnitsController < ApplicationController if @unit.destroy flash[:notice] = t(".success") end - redirect_to units_url + run_and_render :index end private diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1d5609e..4c57128 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -98,6 +98,10 @@ module ApplicationHelper end.join.html_safe end + def render_no_items + tag.tr tag.td t('.no_items'), colspan: 10, class: 'hint' + end + private def image_element_to(type, name, image = nil, options = nil, html_options = {}) diff --git a/app/views/units/_index.html.erb b/app/views/units/_index.html.erb deleted file mode 100644 index 5cb6164..0000000 --- a/app/views/units/_index.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% Unit.each_with_level(@units) do |unit, level| %> -