Browse Source

lazy me generates a whole scaffold for certificates

master
Georg Hopp 10 years ago
parent
commit
a291fb6de0
  1. 3
      app/assets/javascripts/certificates.coffee
  2. 3
      app/assets/stylesheets/certificates.scss
  3. 73
      app/assets/stylesheets/scaffolds.scss
  4. 74
      app/controllers/certificates_controller.rb
  5. 2
      app/helpers/certificates_helper.rb
  6. 29
      app/views/certificates/_form.html.erb
  7. 6
      app/views/certificates/edit.html.erb
  8. 31
      app/views/certificates/index.html.erb
  9. 4
      app/views/certificates/index.json.jbuilder
  10. 5
      app/views/certificates/new.html.erb
  11. 19
      app/views/certificates/show.html.erb
  12. 1
      app/views/certificates/show.json.jbuilder
  13. 1
      config/routes.rb
  14. 49
      test/controllers/certificates_controller_test.rb

3
app/assets/javascripts/certificates.coffee

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

3
app/assets/stylesheets/certificates.scss

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

73
app/assets/stylesheets/scaffolds.scss

@ -0,0 +1,73 @@
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;
}
}

74
app/controllers/certificates_controller.rb

@ -0,0 +1,74 @@
class CertificatesController < ApplicationController
before_action :set_certificate, only: [:show, :edit, :update, :destroy]
# GET /certificates
# GET /certificates.json
def index
@certificates = Certificate.all
end
# GET /certificates/1
# GET /certificates/1.json
def show
end
# GET /certificates/new
def new
@certificate = Certificate.new
end
# GET /certificates/1/edit
def edit
end
# POST /certificates
# POST /certificates.json
def create
@certificate = Certificate.new(certificate_params)
respond_to do |format|
if @certificate.save
format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' }
format.json { render :show, status: :created, location: @certificate }
else
format.html { render :new }
format.json { render json: @certificate.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /certificates/1
# PATCH/PUT /certificates/1.json
def update
respond_to do |format|
if @certificate.update(certificate_params)
format.html { redirect_to @certificate, notice: 'Certificate was successfully updated.' }
format.json { render :show, status: :ok, location: @certificate }
else
format.html { render :edit }
format.json { render json: @certificate.errors, status: :unprocessable_entity }
end
end
end
# DELETE /certificates/1
# DELETE /certificates/1.json
def destroy
@certificate.destroy
respond_to do |format|
format.html { redirect_to certificates_url, notice: 'Certificate was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_certificate
@certificate = Certificate.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def certificate_params
params.require(:certificate).permit(:key, :cert, :active)
end
end

2
app/helpers/certificates_helper.rb

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

29
app/views/certificates/_form.html.erb

@ -0,0 +1,29 @@
<%= form_for(@certificate) do |f| %>
<% if @certificate.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@certificate.errors.count, "error") %> prohibited this certificate from being saved:</h2>
<ul>
<% @certificate.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :key %><br>
<%= f.text_area :key %>
</div>
<div class="field">
<%= f.label :cert %><br>
<%= f.text_area :cert %>
</div>
<div class="field">
<%= f.label :active %><br>
<%= f.check_box :active %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

6
app/views/certificates/edit.html.erb

@ -0,0 +1,6 @@
<h1>Editing Certificate</h1>
<%= render 'form' %>
<%= link_to 'Show', @certificate %> |
<%= link_to 'Back', certificates_path %>

31
app/views/certificates/index.html.erb

@ -0,0 +1,31 @@
<p id="notice"><%= notice %></p>
<h1>Listing Certificates</h1>
<table>
<thead>
<tr>
<th>Key</th>
<th>Cert</th>
<th>Active</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @certificates.each do |certificate| %>
<tr>
<td><%= certificate.key %></td>
<td><%= certificate.cert %></td>
<td><%= certificate.active %></td>
<td><%= link_to 'Show', certificate %></td>
<td><%= link_to 'Edit', edit_certificate_path(certificate) %></td>
<td><%= link_to 'Destroy', certificate, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Certificate', new_certificate_path %>

4
app/views/certificates/index.json.jbuilder

@ -0,0 +1,4 @@
json.array!(@certificates) do |certificate|
json.extract! certificate, :id, :key, :cert, :active
json.url certificate_url(certificate, format: :json)
end

5
app/views/certificates/new.html.erb

@ -0,0 +1,5 @@
<h1>New Certificate</h1>
<%= render 'form' %>
<%= link_to 'Back', certificates_path %>

19
app/views/certificates/show.html.erb

@ -0,0 +1,19 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Key:</strong>
<%= @certificate.key %>
</p>
<p>
<strong>Cert:</strong>
<%= @certificate.cert %>
</p>
<p>
<strong>Active:</strong>
<%= @certificate.active %>
</p>
<%= link_to 'Edit', edit_certificate_path(@certificate) %> |
<%= link_to 'Back', certificates_path %>

1
app/views/certificates/show.json.jbuilder

@ -0,0 +1 @@
json.extract! @certificate, :id, :key, :cert, :active, :created_at, :updated_at

1
config/routes.rb

@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :certificates
get 'dashboard/index'
# The priority is based upon order of creation: first created -> highest priority.

49
test/controllers/certificates_controller_test.rb

@ -0,0 +1,49 @@
require 'test_helper'
class CertificatesControllerTest < ActionController::TestCase
setup do
@certificate = certificates(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:certificates)
end
test "should get new" do
get :new
assert_response :success
end
test "should create certificate" do
assert_difference('Certificate.count') do
post :create, certificate: { active: @certificate.active, cert: @certificate.cert, key: @certificate.key }
end
assert_redirected_to certificate_path(assigns(:certificate))
end
test "should show certificate" do
get :show, id: @certificate
assert_response :success
end
test "should get edit" do
get :edit, id: @certificate
assert_response :success
end
test "should update certificate" do
patch :update, id: @certificate, certificate: { active: @certificate.active, cert: @certificate.cert, key: @certificate.key }
assert_redirected_to certificate_path(assigns(:certificate))
end
test "should destroy certificate" do
assert_difference('Certificate.count', -1) do
delete :destroy, id: @certificate
end
assert_redirected_to certificates_path
end
end
Loading…
Cancel
Save