Browse Source

lazy me generates a whole scaffold for hosts

master
Georg Hopp 10 years ago
parent
commit
14802473f7
  1. 3
      app/assets/javascripts/lxd_hosts.coffee
  2. 3
      app/assets/stylesheets/lxd_hosts.scss
  3. 74
      app/controllers/lxd_hosts_controller.rb
  4. 2
      app/helpers/lxd_hosts_helper.rb
  5. 33
      app/views/lxd_hosts/_form.html.erb
  6. 6
      app/views/lxd_hosts/edit.html.erb
  7. 29
      app/views/lxd_hosts/index.html.erb
  8. 4
      app/views/lxd_hosts/index.json.jbuilder
  9. 5
      app/views/lxd_hosts/new.html.erb
  10. 14
      app/views/lxd_hosts/show.html.erb
  11. 1
      app/views/lxd_hosts/show.json.jbuilder
  12. 1
      config/routes.rb
  13. 49
      test/controllers/lxd_hosts_controller_test.rb

3
app/assets/javascripts/lxd_hosts.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/lxd_hosts.scss

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

74
app/controllers/lxd_hosts_controller.rb

@ -0,0 +1,74 @@
class LxdHostsController < ApplicationController
before_action :set_lxd_host, only: [:show, :edit, :update, :destroy]
# GET /lxd_hosts
# GET /lxd_hosts.json
def index
@lxd_hosts = LxdHost.all
end
# GET /lxd_hosts/1
# GET /lxd_hosts/1.json
def show
end
# GET /lxd_hosts/new
def new
@lxd_host = LxdHost.new
end
# GET /lxd_hosts/1/edit
def edit
end
# POST /lxd_hosts
# POST /lxd_hosts.json
def create
@lxd_host = LxdHost.new(lxd_host_params)
respond_to do |format|
if @lxd_host.save
format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully created.' }
format.json { render :show, status: :created, location: @lxd_host }
else
format.html { render :new }
format.json { render json: @lxd_host.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /lxd_hosts/1
# PATCH/PUT /lxd_hosts/1.json
def update
respond_to do |format|
if @lxd_host.update(lxd_host_params)
format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully updated.' }
format.json { render :show, status: :ok, location: @lxd_host }
else
format.html { render :edit }
format.json { render json: @lxd_host.errors, status: :unprocessable_entity }
end
end
end
# DELETE /lxd_hosts/1
# DELETE /lxd_hosts/1.json
def destroy
@lxd_host.destroy
respond_to do |format|
format.html { redirect_to lxd_hosts_url, notice: 'Lxd host was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_lxd_host
@lxd_host = LxdHost.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def lxd_host_params
params.require(:lxd_host).permit(:name, :uri, :password, :password_confirmation)
end
end

2
app/helpers/lxd_hosts_helper.rb

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

33
app/views/lxd_hosts/_form.html.erb

@ -0,0 +1,33 @@
<%= form_for(@lxd_host) do |f| %>
<% if @lxd_host.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@lxd_host.errors.count, "error") %> prohibited this lxd_host from being saved:</h2>
<ul>
<% @lxd_host.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_area :name %>
</div>
<div class="field">
<%= f.label :uri %><br>
<%= f.text_area :uri %>
</div>
<div class="field">
<%= f.label :password %><br>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

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

@ -0,0 +1,6 @@
<h1>Editing Lxd Host</h1>
<%= render 'form' %>
<%= link_to 'Show', @lxd_host %> |
<%= link_to 'Back', lxd_hosts_path %>

29
app/views/lxd_hosts/index.html.erb

@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>
<h1>Listing Lxd Hosts</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Uri</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @lxd_hosts.each do |lxd_host| %>
<tr>
<td><%= lxd_host.name %></td>
<td><%= lxd_host.uri %></td>
<td><%= link_to 'Show', lxd_host %></td>
<td><%= link_to 'Edit', edit_lxd_host_path(lxd_host) %></td>
<td><%= link_to 'Destroy', lxd_host, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Lxd host', new_lxd_host_path %>

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

@ -0,0 +1,4 @@
json.array!(@lxd_hosts) do |lxd_host|
json.extract! lxd_host, :id, :name, :uri
json.url lxd_host_url(lxd_host, format: :json)
end

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

@ -0,0 +1,5 @@
<h1>New Lxd Host</h1>
<%= render 'form' %>
<%= link_to 'Back', lxd_hosts_path %>

14
app/views/lxd_hosts/show.html.erb

@ -0,0 +1,14 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @lxd_host.name %>
</p>
<p>
<strong>Uri:</strong>
<%= @lxd_host.uri %>
</p>
<%= link_to 'Edit', edit_lxd_host_path(@lxd_host) %> |
<%= link_to 'Back', lxd_hosts_path %>

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

@ -0,0 +1 @@
json.extract! @lxd_host, :id, :name, :uri, :created_at, :updated_at

1
config/routes.rb

@ -1,4 +1,5 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :lxd_hosts
resources :certificates resources :certificates
get 'dashboard/index' get 'dashboard/index'

49
test/controllers/lxd_hosts_controller_test.rb

@ -0,0 +1,49 @@
require 'test_helper'
class LxdHostsControllerTest < ActionController::TestCase
setup do
@lxd_host = lxd_hosts(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:lxd_hosts)
end
test "should get new" do
get :new
assert_response :success
end
test "should create lxd_host" do
assert_difference('LxdHost.count') do
post :create, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri }
end
assert_redirected_to lxd_host_path(assigns(:lxd_host))
end
test "should show lxd_host" do
get :show, id: @lxd_host
assert_response :success
end
test "should get edit" do
get :edit, id: @lxd_host
assert_response :success
end
test "should update lxd_host" do
patch :update, id: @lxd_host, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri }
assert_redirected_to lxd_host_path(assigns(:lxd_host))
end
test "should destroy lxd_host" do
assert_difference('LxdHost.count', -1) do
delete :destroy, id: @lxd_host
end
assert_redirected_to lxd_hosts_path
end
end
Loading…
Cancel
Save