Scaffold error template attributes
This commit is contained in:
86
app/controllers/error_template_attributes_controller.rb
Normal file
86
app/controllers/error_template_attributes_controller.rb
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
class ErrorTemplateAttributesController < ApplicationController
|
||||||
|
before_action :set_error_template_attribute, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
|
def authorize!
|
||||||
|
authorize(@error_template_attributes || @error_template_attribute)
|
||||||
|
end
|
||||||
|
private :authorize!
|
||||||
|
|
||||||
|
# GET /error_template_attributes
|
||||||
|
# GET /error_template_attributes.json
|
||||||
|
def index
|
||||||
|
@error_template_attributes = ErrorTemplateAttribute.all.order(:id).paginate(page: params[:page])
|
||||||
|
authorize!
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /error_template_attributes/1
|
||||||
|
# GET /error_template_attributes/1.json
|
||||||
|
def show
|
||||||
|
authorize!
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /error_template_attributes/new
|
||||||
|
def new
|
||||||
|
@error_template_attribute = ErrorTemplateAttribute.new
|
||||||
|
authorize!
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /error_template_attributes/1/edit
|
||||||
|
def edit
|
||||||
|
authorize!
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /error_template_attributes
|
||||||
|
# POST /error_template_attributes.json
|
||||||
|
def create
|
||||||
|
@error_template_attribute = ErrorTemplateAttribute.new(error_template_attribute_params)
|
||||||
|
authorize!
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @error_template_attribute.save
|
||||||
|
format.html { redirect_to @error_template_attribute, notice: 'Error template attribute was successfully created.' }
|
||||||
|
format.json { render :show, status: :created, location: @error_template_attribute }
|
||||||
|
else
|
||||||
|
format.html { render :new }
|
||||||
|
format.json { render json: @error_template_attribute.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PATCH/PUT /error_template_attributes/1
|
||||||
|
# PATCH/PUT /error_template_attributes/1.json
|
||||||
|
def update
|
||||||
|
authorize!
|
||||||
|
respond_to do |format|
|
||||||
|
if @error_template_attribute.update(error_template_attribute_params)
|
||||||
|
format.html { redirect_to @error_template_attribute, notice: 'Error template attribute was successfully updated.' }
|
||||||
|
format.json { render :show, status: :ok, location: @error_template_attribute }
|
||||||
|
else
|
||||||
|
format.html { render :edit }
|
||||||
|
format.json { render json: @error_template_attribute.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /error_template_attributes/1
|
||||||
|
# DELETE /error_template_attributes/1.json
|
||||||
|
def destroy
|
||||||
|
authorize!
|
||||||
|
@error_template_attribute.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to error_template_attributes_url, notice: 'Error template attribute was successfully destroyed.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
def set_error_template_attribute
|
||||||
|
@error_template_attribute = ErrorTemplateAttribute.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
def error_template_attribute_params
|
||||||
|
params.fetch(:error_template_attribute, {})
|
||||||
|
end
|
||||||
|
end
|
2
app/helpers/error_template_attributes_helper.rb
Normal file
2
app/helpers/error_template_attributes_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module ErrorTemplateAttributesHelper
|
||||||
|
end
|
@ -1,3 +1,7 @@
|
|||||||
class ErrorTemplateAttribute < ActiveRecord::Base
|
class ErrorTemplateAttribute < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :error_template
|
has_and_belongs_to_many :error_template
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#{id} [#{key}]"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
3
app/policies/error_template_attribute_policy.rb
Normal file
3
app/policies/error_template_attribute_policy.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class ErrorTemplateAttributePolicy < AdminOnlyPolicy
|
||||||
|
|
||||||
|
end
|
16
app/views/error_template_attributes/_form.html.slim
Normal file
16
app/views/error_template_attributes/_form.html.slim
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
= form_for(@error_template_attribute) do |f|
|
||||||
|
= render('shared/form_errors', object: @error_template_attribute)
|
||||||
|
.form-group
|
||||||
|
= f.label(:key)
|
||||||
|
= f.text_field(:key, class: 'form-control', required: true)
|
||||||
|
.form-group
|
||||||
|
= f.label(:description)
|
||||||
|
= f.text_field(:description, class: 'form-control')
|
||||||
|
.form-group
|
||||||
|
= f.label(:regex)
|
||||||
|
= f.text_field(:regex, class: 'form-control', required: true)
|
||||||
|
.help-block == t('error_templates.hints.signature')
|
||||||
|
.form-group
|
||||||
|
= f.check_box(:important)
|
||||||
|
= t('activerecord.attributes.error_template_attribute.important')
|
||||||
|
.actions = render('shared/submit_button', f: f, object: @error_template_attribute)
|
3
app/views/error_template_attributes/edit.html.slim
Normal file
3
app/views/error_template_attributes/edit.html.slim
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
h1 = @error_template_attribute
|
||||||
|
|
||||||
|
= render('form')
|
28
app/views/error_template_attributes/index.html.slim
Normal file
28
app/views/error_template_attributes/index.html.slim
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
h1 = ErrorTemplateAttribute.model_name.human(count: 2)
|
||||||
|
|
||||||
|
.table-responsive
|
||||||
|
table.sortable.table
|
||||||
|
thead
|
||||||
|
tr
|
||||||
|
th
|
||||||
|
th = t('activerecord.attributes.error_template_attribute.key')
|
||||||
|
th = t('activerecord.attributes.error_template_attribute.description')
|
||||||
|
th = t('activerecord.attributes.error_template_attribute.regex')
|
||||||
|
th colspan=5 = t('shared.actions')
|
||||||
|
tbody
|
||||||
|
- @error_template_attributes.each do |error_template_attribute|
|
||||||
|
tr
|
||||||
|
td
|
||||||
|
- if error_template_attribute.important
|
||||||
|
span class="fa fa-star" aria-hidden="true"
|
||||||
|
- else
|
||||||
|
span class="fa fa-star-o" aria-hidden="true"
|
||||||
|
td = error_template_attribute.key
|
||||||
|
td = error_template_attribute.description
|
||||||
|
td = error_template_attribute.regex
|
||||||
|
td = link_to(t('shared.show'), error_template_attribute)
|
||||||
|
td = link_to(t('shared.edit'), edit_error_template_attribute_path(error_template_attribute))
|
||||||
|
td = link_to(t('shared.destroy'), error_template_attribute, data: {confirm: t('shared.confirm_destroy')}, method: :delete)
|
||||||
|
|
||||||
|
= render('shared/pagination', collection: @error_template_attributes)
|
||||||
|
p = render('shared/new_button', model: ErrorTemplateAttribute)
|
3
app/views/error_template_attributes/new.html.slim
Normal file
3
app/views/error_template_attributes/new.html.slim
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
h1 = t('shared.new_model', model: ErrorTemplateAttribute.model_name.human)
|
||||||
|
|
||||||
|
= render('form')
|
8
app/views/error_template_attributes/show.html.slim
Normal file
8
app/views/error_template_attributes/show.html.slim
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
h1
|
||||||
|
= @error_template_attribute
|
||||||
|
= render('shared/edit_button', object: @error_template_attribute)
|
||||||
|
|
||||||
|
- [:key, :description, :regex, :important].each do |attribute|
|
||||||
|
= row(label: "error_template_attribute.#{attribute}", value: @error_template_attribute.send(attribute))
|
||||||
|
|
||||||
|
// todo: used by
|
@ -15,9 +15,9 @@ h3
|
|||||||
thead
|
thead
|
||||||
tr
|
tr
|
||||||
th
|
th
|
||||||
th = t('activerecord.attributes.error_template_attributes.key')
|
th = t('activerecord.attributes.error_template_attribute.key')
|
||||||
th = t('activerecord.attributes.error_template_attributes.description')
|
th = t('activerecord.attributes.error_template_attribute.description')
|
||||||
th = t('activerecord.attributes.error_template_attributes.regex')
|
th = t('activerecord.attributes.error_template_attribute.regex')
|
||||||
tbody
|
tbody
|
||||||
- @error_template.error_template_attributes.order(:important).each do |attribute|
|
- @error_template.error_template_attributes.order(:important).each do |attribute|
|
||||||
tr
|
tr
|
||||||
|
@ -114,7 +114,7 @@ de:
|
|||||||
signature: Regulärer Ausdruck
|
signature: Regulärer Ausdruck
|
||||||
description: Beschreibung
|
description: Beschreibung
|
||||||
hint: Hinweis
|
hint: Hinweis
|
||||||
error_template_attributes:
|
error_template_attribute:
|
||||||
important: "Wichtig"
|
important: "Wichtig"
|
||||||
key: "Name"
|
key: "Name"
|
||||||
description: "Beschreibung"
|
description: "Beschreibung"
|
||||||
|
@ -135,7 +135,7 @@ en:
|
|||||||
signature: Signature Regular Expression
|
signature: Signature Regular Expression
|
||||||
description: Description
|
description: Description
|
||||||
hint: Hint
|
hint: Hint
|
||||||
error_template_attributes:
|
error_template_attribute:
|
||||||
important: "Important"
|
important: "Important"
|
||||||
key: "Identifier"
|
key: "Identifier"
|
||||||
description: "Description"
|
description: "Description"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
|
FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
resources :error_template_attributes
|
||||||
resources :error_templates
|
resources :error_templates
|
||||||
resources :file_templates do
|
resources :file_templates do
|
||||||
collection do
|
collection do
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ErrorTemplateAttributesControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@error_template_attribute = error_template_attributes(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:error_template_attributes)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create error_template_attribute" do
|
||||||
|
assert_difference('ErrorTemplateAttribute.count') do
|
||||||
|
post :create, error_template_attribute: { }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to error_template_attribute_path(assigns(:error_template_attribute))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show error_template_attribute" do
|
||||||
|
get :show, id: @error_template_attribute
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @error_template_attribute
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update error_template_attribute" do
|
||||||
|
patch :update, id: @error_template_attribute, error_template_attribute: { }
|
||||||
|
assert_redirected_to error_template_attribute_path(assigns(:error_template_attribute))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy error_template_attribute" do
|
||||||
|
assert_difference('ErrorTemplateAttribute.count', -1) do
|
||||||
|
delete :destroy, id: @error_template_attribute
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to error_template_attributes_path
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user