Commit 14802473f7019c71acd479271ab0a59fee40595b

Authored by Georg Hopp
1 parent a291fb6d

lazy me generates a whole scaffold for hosts

  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 lxd_hosts controller here.
  2 +// They will automatically be included in application.css.
  3 +// You can use Sass (SCSS) here: http://sass-lang.com/
... ...
  1 +class LxdHostsController < ApplicationController
  2 + before_action :set_lxd_host, only: [:show, :edit, :update, :destroy]
  3 +
  4 + # GET /lxd_hosts
  5 + # GET /lxd_hosts.json
  6 + def index
  7 + @lxd_hosts = LxdHost.all
  8 + end
  9 +
  10 + # GET /lxd_hosts/1
  11 + # GET /lxd_hosts/1.json
  12 + def show
  13 + end
  14 +
  15 + # GET /lxd_hosts/new
  16 + def new
  17 + @lxd_host = LxdHost.new
  18 + end
  19 +
  20 + # GET /lxd_hosts/1/edit
  21 + def edit
  22 + end
  23 +
  24 + # POST /lxd_hosts
  25 + # POST /lxd_hosts.json
  26 + def create
  27 + @lxd_host = LxdHost.new(lxd_host_params)
  28 +
  29 + respond_to do |format|
  30 + if @lxd_host.save
  31 + format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully created.' }
  32 + format.json { render :show, status: :created, location: @lxd_host }
  33 + else
  34 + format.html { render :new }
  35 + format.json { render json: @lxd_host.errors, status: :unprocessable_entity }
  36 + end
  37 + end
  38 + end
  39 +
  40 + # PATCH/PUT /lxd_hosts/1
  41 + # PATCH/PUT /lxd_hosts/1.json
  42 + def update
  43 + respond_to do |format|
  44 + if @lxd_host.update(lxd_host_params)
  45 + format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully updated.' }
  46 + format.json { render :show, status: :ok, location: @lxd_host }
  47 + else
  48 + format.html { render :edit }
  49 + format.json { render json: @lxd_host.errors, status: :unprocessable_entity }
  50 + end
  51 + end
  52 + end
  53 +
  54 + # DELETE /lxd_hosts/1
  55 + # DELETE /lxd_hosts/1.json
  56 + def destroy
  57 + @lxd_host.destroy
  58 + respond_to do |format|
  59 + format.html { redirect_to lxd_hosts_url, notice: 'Lxd host 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_lxd_host
  67 + @lxd_host = LxdHost.find(params[:id])
  68 + end
  69 +
  70 + # Never trust parameters from the scary internet, only allow the white list through.
  71 + def lxd_host_params
  72 + params.require(:lxd_host).permit(:name, :uri, :password, :password_confirmation)
  73 + end
  74 +end
... ...
  1 +module LxdHostsHelper
  2 +end
... ...
  1 +<%= form_for(@lxd_host) do |f| %>
  2 + <% if @lxd_host.errors.any? %>
  3 + <div id="error_explanation">
  4 + <h2><%= pluralize(@lxd_host.errors.count, "error") %> prohibited this lxd_host from being saved:</h2>
  5 +
  6 + <ul>
  7 + <% @lxd_host.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 :name %><br>
  16 + <%= f.text_area :name %>
  17 + </div>
  18 + <div class="field">
  19 + <%= f.label :uri %><br>
  20 + <%= f.text_area :uri %>
  21 + </div>
  22 + <div class="field">
  23 + <%= f.label :password %><br>
  24 + <%= f.password_field :password %>
  25 + </div>
  26 + <div class="field">
  27 + <%= f.label :password_confirmation %><br>
  28 + <%= f.password_field :password_confirmation %>
  29 + </div>
  30 + <div class="actions">
  31 + <%= f.submit %>
  32 + </div>
  33 +<% end %>
... ...
  1 +<h1>Editing Lxd Host</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Show', @lxd_host %> |
  6 +<%= link_to 'Back', lxd_hosts_path %>
... ...
  1 +<p id="notice"><%= notice %></p>
  2 +
  3 +<h1>Listing Lxd Hosts</h1>
  4 +
  5 +<table>
  6 + <thead>
  7 + <tr>
  8 + <th>Name</th>
  9 + <th>Uri</th>
  10 + <th colspan="3"></th>
  11 + </tr>
  12 + </thead>
  13 +
  14 + <tbody>
  15 + <% @lxd_hosts.each do |lxd_host| %>
  16 + <tr>
  17 + <td><%= lxd_host.name %></td>
  18 + <td><%= lxd_host.uri %></td>
  19 + <td><%= link_to 'Show', lxd_host %></td>
  20 + <td><%= link_to 'Edit', edit_lxd_host_path(lxd_host) %></td>
  21 + <td><%= link_to 'Destroy', lxd_host, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  22 + </tr>
  23 + <% end %>
  24 + </tbody>
  25 +</table>
  26 +
  27 +<br>
  28 +
  29 +<%= link_to 'New Lxd host', new_lxd_host_path %>
... ...
  1 +json.array!(@lxd_hosts) do |lxd_host|
  2 + json.extract! lxd_host, :id, :name, :uri
  3 + json.url lxd_host_url(lxd_host, format: :json)
  4 +end
... ...
  1 +<h1>New Lxd Host</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Back', lxd_hosts_path %>
... ...
  1 +<p id="notice"><%= notice %></p>
  2 +
  3 +<p>
  4 + <strong>Name:</strong>
  5 + <%= @lxd_host.name %>
  6 +</p>
  7 +
  8 +<p>
  9 + <strong>Uri:</strong>
  10 + <%= @lxd_host.uri %>
  11 +</p>
  12 +
  13 +<%= link_to 'Edit', edit_lxd_host_path(@lxd_host) %> |
  14 +<%= link_to 'Back', lxd_hosts_path %>
... ...
  1 +json.extract! @lxd_host, :id, :name, :uri, :created_at, :updated_at
... ...
1 1 Rails.application.routes.draw do
  2 + resources :lxd_hosts
2 3 resources :certificates
3 4 get 'dashboard/index'
4 5
... ...
  1 +require 'test_helper'
  2 +
  3 +class LxdHostsControllerTest < ActionController::TestCase
  4 + setup do
  5 + @lxd_host = lxd_hosts(:one)
  6 + end
  7 +
  8 + test "should get index" do
  9 + get :index
  10 + assert_response :success
  11 + assert_not_nil assigns(:lxd_hosts)
  12 + end
  13 +
  14 + test "should get new" do
  15 + get :new
  16 + assert_response :success
  17 + end
  18 +
  19 + test "should create lxd_host" do
  20 + assert_difference('LxdHost.count') do
  21 + post :create, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri }
  22 + end
  23 +
  24 + assert_redirected_to lxd_host_path(assigns(:lxd_host))
  25 + end
  26 +
  27 + test "should show lxd_host" do
  28 + get :show, id: @lxd_host
  29 + assert_response :success
  30 + end
  31 +
  32 + test "should get edit" do
  33 + get :edit, id: @lxd_host
  34 + assert_response :success
  35 + end
  36 +
  37 + test "should update lxd_host" do
  38 + patch :update, id: @lxd_host, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri }
  39 + assert_redirected_to lxd_host_path(assigns(:lxd_host))
  40 + end
  41 +
  42 + test "should destroy lxd_host" do
  43 + assert_difference('LxdHost.count', -1) do
  44 + delete :destroy, id: @lxd_host
  45 + end
  46 +
  47 + assert_redirected_to lxd_hosts_path
  48 + end
  49 +end
... ...
Please register or login to post a comment