Commit a291fb6de048530507c8a2e35aa3bac46097ecd2

Authored by Georg Hopp
1 parent 2f2b7b7e

lazy me generates a whole scaffold for certificates

  1 +# Place all the behaviors and hooks related to the matching controller here.
  2 +# All this logic will automatically be available in application.js.
  3 +# You can use CoffeeScript in this file: http://coffeescript.org/
  1 +// Place all the styles related to the certificates controller here.
  2 +// They will automatically be included in application.css.
  3 +// You can use Sass (SCSS) here: http://sass-lang.com/
  1 +body {
  2 + background-color: #fff;
  3 + color: #333;
  4 + font-family: verdana, arial, helvetica, sans-serif;
  5 + font-size: 13px;
  6 + line-height: 18px;
  7 +}
  8 +
  9 +p, ol, ul, td {
  10 + font-family: verdana, arial, helvetica, sans-serif;
  11 + font-size: 13px;
  12 + line-height: 18px;
  13 +}
  14 +
  15 +pre {
  16 + background-color: #eee;
  17 + padding: 10px;
  18 + font-size: 11px;
  19 +}
  20 +
  21 +a {
  22 + color: #000;
  23 +
  24 + &:visited {
  25 + color: #666;
  26 + }
  27 +
  28 + &:hover {
  29 + color: #fff;
  30 + background-color: #000;
  31 + }
  32 +}
  33 +
  34 +div {
  35 + &.field, &.actions {
  36 + margin-bottom: 10px;
  37 + }
  38 +}
  39 +
  40 +#notice {
  41 + color: green;
  42 +}
  43 +
  44 +.field_with_errors {
  45 + padding: 2px;
  46 + background-color: red;
  47 + display: table;
  48 +}
  49 +
  50 +#error_explanation {
  51 + width: 450px;
  52 + border: 2px solid red;
  53 + padding: 7px;
  54 + padding-bottom: 0;
  55 + margin-bottom: 20px;
  56 + background-color: #f0f0f0;
  57 +
  58 + h2 {
  59 + text-align: left;
  60 + font-weight: bold;
  61 + padding: 5px 5px 5px 15px;
  62 + font-size: 12px;
  63 + margin: -7px;
  64 + margin-bottom: 0px;
  65 + background-color: #c00;
  66 + color: #fff;
  67 + }
  68 +
  69 + ul li {
  70 + font-size: 12px;
  71 + list-style: square;
  72 + }
  73 +}
  1 +class CertificatesController < ApplicationController
  2 + before_action :set_certificate, only: [:show, :edit, :update, :destroy]
  3 +
  4 + # GET /certificates
  5 + # GET /certificates.json
  6 + def index
  7 + @certificates = Certificate.all
  8 + end
  9 +
  10 + # GET /certificates/1
  11 + # GET /certificates/1.json
  12 + def show
  13 + end
  14 +
  15 + # GET /certificates/new
  16 + def new
  17 + @certificate = Certificate.new
  18 + end
  19 +
  20 + # GET /certificates/1/edit
  21 + def edit
  22 + end
  23 +
  24 + # POST /certificates
  25 + # POST /certificates.json
  26 + def create
  27 + @certificate = Certificate.new(certificate_params)
  28 +
  29 + respond_to do |format|
  30 + if @certificate.save
  31 + format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' }
  32 + format.json { render :show, status: :created, location: @certificate }
  33 + else
  34 + format.html { render :new }
  35 + format.json { render json: @certificate.errors, status: :unprocessable_entity }
  36 + end
  37 + end
  38 + end
  39 +
  40 + # PATCH/PUT /certificates/1
  41 + # PATCH/PUT /certificates/1.json
  42 + def update
  43 + respond_to do |format|
  44 + if @certificate.update(certificate_params)
  45 + format.html { redirect_to @certificate, notice: 'Certificate was successfully updated.' }
  46 + format.json { render :show, status: :ok, location: @certificate }
  47 + else
  48 + format.html { render :edit }
  49 + format.json { render json: @certificate.errors, status: :unprocessable_entity }
  50 + end
  51 + end
  52 + end
  53 +
  54 + # DELETE /certificates/1
  55 + # DELETE /certificates/1.json
  56 + def destroy
  57 + @certificate.destroy
  58 + respond_to do |format|
  59 + format.html { redirect_to certificates_url, notice: 'Certificate was successfully destroyed.' }
  60 + format.json { head :no_content }
  61 + end
  62 + end
  63 +
  64 + private
  65 + # Use callbacks to share common setup or constraints between actions.
  66 + def set_certificate
  67 + @certificate = Certificate.find(params[:id])
  68 + end
  69 +
  70 + # Never trust parameters from the scary internet, only allow the white list through.
  71 + def certificate_params
  72 + params.require(:certificate).permit(:key, :cert, :active)
  73 + end
  74 +end
  1 +module CertificatesHelper
  2 +end
  1 +<%= form_for(@certificate) do |f| %>
  2 + <% if @certificate.errors.any? %>
  3 + <div id="error_explanation">
  4 + <h2><%= pluralize(@certificate.errors.count, "error") %> prohibited this certificate from being saved:</h2>
  5 +
  6 + <ul>
  7 + <% @certificate.errors.full_messages.each do |message| %>
  8 + <li><%= message %></li>
  9 + <% end %>
  10 + </ul>
  11 + </div>
  12 + <% end %>
  13 +
  14 + <div class="field">
  15 + <%= f.label :key %><br>
  16 + <%= f.text_area :key %>
  17 + </div>
  18 + <div class="field">
  19 + <%= f.label :cert %><br>
  20 + <%= f.text_area :cert %>
  21 + </div>
  22 + <div class="field">
  23 + <%= f.label :active %><br>
  24 + <%= f.check_box :active %>
  25 + </div>
  26 + <div class="actions">
  27 + <%= f.submit %>
  28 + </div>
  29 +<% end %>
  1 +<h1>Editing Certificate</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Show', @certificate %> |
  6 +<%= link_to 'Back', certificates_path %>
  1 +<p id="notice"><%= notice %></p>
  2 +
  3 +<h1>Listing Certificates</h1>
  4 +
  5 +<table>
  6 + <thead>
  7 + <tr>
  8 + <th>Key</th>
  9 + <th>Cert</th>
  10 + <th>Active</th>
  11 + <th colspan="3"></th>
  12 + </tr>
  13 + </thead>
  14 +
  15 + <tbody>
  16 + <% @certificates.each do |certificate| %>
  17 + <tr>
  18 + <td><%= certificate.key %></td>
  19 + <td><%= certificate.cert %></td>
  20 + <td><%= certificate.active %></td>
  21 + <td><%= link_to 'Show', certificate %></td>
  22 + <td><%= link_to 'Edit', edit_certificate_path(certificate) %></td>
  23 + <td><%= link_to 'Destroy', certificate, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  24 + </tr>
  25 + <% end %>
  26 + </tbody>
  27 +</table>
  28 +
  29 +<br>
  30 +
  31 +<%= link_to 'New Certificate', new_certificate_path %>
  1 +json.array!(@certificates) do |certificate|
  2 + json.extract! certificate, :id, :key, :cert, :active
  3 + json.url certificate_url(certificate, format: :json)
  4 +end
  1 +<h1>New Certificate</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Back', certificates_path %>
  1 +<p id="notice"><%= notice %></p>
  2 +
  3 +<p>
  4 + <strong>Key:</strong>
  5 + <%= @certificate.key %>
  6 +</p>
  7 +
  8 +<p>
  9 + <strong>Cert:</strong>
  10 + <%= @certificate.cert %>
  11 +</p>
  12 +
  13 +<p>
  14 + <strong>Active:</strong>
  15 + <%= @certificate.active %>
  16 +</p>
  17 +
  18 +<%= link_to 'Edit', edit_certificate_path(@certificate) %> |
  19 +<%= link_to 'Back', certificates_path %>
  1 +json.extract! @certificate, :id, :key, :cert, :active, :created_at, :updated_at
1 Rails.application.routes.draw do 1 Rails.application.routes.draw do
  2 + resources :certificates
2 get 'dashboard/index' 3 get 'dashboard/index'
3 4
4 # The priority is based upon order of creation: first created -> highest priority. 5 # The priority is based upon order of creation: first created -> highest priority.
  1 +require 'test_helper'
  2 +
  3 +class CertificatesControllerTest < ActionController::TestCase
  4 + setup do
  5 + @certificate = certificates(:one)
  6 + end
  7 +
  8 + test "should get index" do
  9 + get :index
  10 + assert_response :success
  11 + assert_not_nil assigns(:certificates)
  12 + end
  13 +
  14 + test "should get new" do
  15 + get :new
  16 + assert_response :success
  17 + end
  18 +
  19 + test "should create certificate" do
  20 + assert_difference('Certificate.count') do
  21 + post :create, certificate: { active: @certificate.active, cert: @certificate.cert, key: @certificate.key }
  22 + end
  23 +
  24 + assert_redirected_to certificate_path(assigns(:certificate))
  25 + end
  26 +
  27 + test "should show certificate" do
  28 + get :show, id: @certificate
  29 + assert_response :success
  30 + end
  31 +
  32 + test "should get edit" do
  33 + get :edit, id: @certificate
  34 + assert_response :success
  35 + end
  36 +
  37 + test "should update certificate" do
  38 + patch :update, id: @certificate, certificate: { active: @certificate.active, cert: @certificate.cert, key: @certificate.key }
  39 + assert_redirected_to certificate_path(assigns(:certificate))
  40 + end
  41 +
  42 + test "should destroy certificate" do
  43 + assert_difference('Certificate.count', -1) do
  44 + delete :destroy, id: @certificate
  45 + end
  46 +
  47 + assert_redirected_to certificates_path
  48 + end
  49 +end
Please register or login to post a comment