Scaffold error_templates UI

This commit is contained in:
Maximilian Grundke
2017-07-12 10:11:52 +02:00
parent d779849e4a
commit 4d38195c99
14 changed files with 275 additions and 0 deletions

View File

@ -0,0 +1,3 @@
// Place all the styles related to the error_templates controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}
div {
&.field, &.actions {
margin-bottom: 10px;
}
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}

View File

@ -0,0 +1,86 @@
class ErrorTemplatesController < ApplicationController
before_action :set_error_template, only: [:show, :edit, :update, :destroy]
def authorize!
authorize(@error_templates || @error_template)
end
private :authorize!
# GET /error_templates
# GET /error_templates.json
def index
@error_templates = ErrorTemplate.all
authorize!
end
# GET /error_templates/1
# GET /error_templates/1.json
def show
authorize!
end
# GET /error_templates/new
def new
@error_template = ErrorTemplate.new
authorize!
end
# GET /error_templates/1/edit
def edit
authorize!
end
# POST /error_templates
# POST /error_templates.json
def create
authorize!
@error_template = ErrorTemplate.new(error_template_params)
respond_to do |format|
if @error_template.save
format.html { redirect_to @error_template, notice: 'Error template was successfully created.' }
format.json { render :show, status: :created, location: @error_template }
else
format.html { render :new }
format.json { render json: @error_template.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /error_templates/1
# PATCH/PUT /error_templates/1.json
def update
authorize!
respond_to do |format|
if @error_template.update(error_template_params)
format.html { redirect_to @error_template, notice: 'Error template was successfully updated.' }
format.json { render :show, status: :ok, location: @error_template }
else
format.html { render :edit }
format.json { render json: @error_template.errors, status: :unprocessable_entity }
end
end
end
# DELETE /error_templates/1
# DELETE /error_templates/1.json
def destroy
authorize!
@error_template.destroy
respond_to do |format|
format.html { redirect_to error_templates_url, notice: 'Error template 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
@error_template = ErrorTemplate.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def error_template_params
params.fetch(:error_template, {})
end
end

View File

@ -0,0 +1,2 @@
module ErrorTemplatesHelper
end

View File

@ -0,0 +1,3 @@
class ErrorTemplatePolicy < AdminOnlyPolicy
end

View File

@ -0,0 +1,17 @@
<%= form_for(@error_template) do |f| %>
<% if @error_template.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@error_template.errors.count, "error") %> prohibited this error_template from being saved:</h2>
<ul>
<% @error_template.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>Editing Error Template</h1>
<%= render 'form' %>
<%= link_to 'Show', @error_template %> |
<%= link_to 'Back', error_templates_path %>

View File

@ -0,0 +1,25 @@
<p id="notice"><%= notice %></p>
<h1>Listing Error Templates</h1>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @error_templates.each do |error_template| %>
<tr>
<td><%= link_to 'Show', error_template %></td>
<td><%= link_to 'Edit', edit_error_template_path(error_template) %></td>
<td><%= link_to 'Destroy', error_template, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Error template', new_error_template_path %>

View File

@ -0,0 +1,4 @@
json.array!(@error_templates) do |error_template|
json.extract! error_template, :id
json.url error_template_url(error_template, format: :json)
end

View File

@ -0,0 +1,5 @@
<h1>New Error Template</h1>
<%= render 'form' %>
<%= link_to 'Back', error_templates_path %>

View File

@ -0,0 +1,4 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_error_template_path(@error_template) %> |
<%= link_to 'Back', error_templates_path %>

View File

@ -0,0 +1 @@
json.extract! @error_template, :id, :created_at, :updated_at

View File

@ -1,6 +1,7 @@
FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
Rails.application.routes.draw do
resources :error_templates
resources :file_templates do
collection do
get 'by_file_type/:file_type_id', as: :by_file_type, action: :by_file_type

View File

@ -0,0 +1,49 @@
require 'test_helper'
class ErrorTemplatesControllerTest < ActionController::TestCase
setup do
@error_template = error_templates(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:error_templates)
end
test "should get new" do
get :new
assert_response :success
end
test "should create error_template" do
assert_difference('ErrorTemplate.count') do
post :create, error_template: { }
end
assert_redirected_to error_template_path(assigns(:error_template))
end
test "should show error_template" do
get :show, id: @error_template
assert_response :success
end
test "should get edit" do
get :edit, id: @error_template
assert_response :success
end
test "should update error_template" do
patch :update, id: @error_template, error_template: { }
assert_redirected_to error_template_path(assigns(:error_template))
end
test "should destroy error_template" do
assert_difference('ErrorTemplate.count', -1) do
delete :destroy, id: @error_template
end
assert_redirected_to error_templates_path
end
end