diff --git a/app/controllers/admin/rules_controller.rb b/app/controllers/admin/rules_controller.rb index 289b6a98c3..d149fd79c3 100644 --- a/app/controllers/admin/rules_controller.rb +++ b/app/controllers/admin/rules_controller.rb @@ -2,13 +2,17 @@ module Admin class RulesController < BaseController - before_action :set_rule, except: [:index, :create] + before_action :set_rule, except: [:index, :new, :create] def index authorize :rule, :index? @rules = Rule.ordered - @rule = Rule.new + end + + def new + authorize :rule, :create? + @rule = Rule.new end def edit diff --git a/app/views/admin/rules/index.html.haml b/app/views/admin/rules/index.html.haml index 5a2789edcf..41bff18d2f 100644 --- a/app/views/admin/rules/index.html.haml +++ b/app/views/admin/rules/index.html.haml @@ -1,21 +1,12 @@ - content_for :page_title do = t('admin.rules.title') -%p= t('admin.rules.description_html') +- content_for :heading_actions do + - if can? :create, :rule + = link_to t('admin.rules.add_new'), new_admin_rule_path, class: 'button' %hr.spacer/ -- if can? :create, :rule - = simple_form_for @rule, url: admin_rules_path do |form| - = render 'shared/error_messages', object: @rule - - = render form - - .actions - = form.button :button, t('admin.rules.add_new'), type: :submit - - %hr.spacer/ - - if @rules.empty? .muted-hint.center-text = t 'admin.rules.empty' diff --git a/app/views/admin/rules/new.html.haml b/app/views/admin/rules/new.html.haml new file mode 100644 index 0000000000..bc93c7df55 --- /dev/null +++ b/app/views/admin/rules/new.html.haml @@ -0,0 +1,14 @@ +- content_for :page_title do + = t('admin.rules.add_new') + +%p= t('admin.rules.description_html') + +%hr.spacer/ + += simple_form_for @rule, url: admin_rules_path do |form| + = render 'shared/error_messages', object: @rule + + = render form + + .actions + = form.button :button, t('admin.rules.add_new'), type: :submit diff --git a/config/routes/admin.rb b/config/routes/admin.rb index d5459a2735..2f7b86162b 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -93,7 +93,7 @@ namespace :admin do end end - resources :rules, only: [:index, :create, :edit, :update, :destroy] + resources :rules, only: [:index, :new, :create, :edit, :update, :destroy] resources :webhooks do member do