Added doamins

This commit is contained in:
2023-05-10 14:29:15 +01:00
parent 1b08798306
commit 843b510395
22 changed files with 304 additions and 5 deletions

View File

@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end

View File

@@ -0,0 +1,70 @@
class DomainsController < ApplicationController
before_action :set_domain, only: %i[ show edit update destroy ]
# GET /domains or /domains.json
def index
@domains = Domain.all
end
# GET /domains/1 or /domains/1.json
def show
end
# GET /domains/new
def new
@domain = Domain.new
end
# GET /domains/1/edit
def edit
end
# POST /domains or /domains.json
def create
@domain = Domain.new(domain_params)
respond_to do |format|
if @domain.save
format.html { redirect_to domain_url(@domain), notice: "Domain was successfully created." }
format.json { render :show, status: :created, location: @domain }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @domain.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /domains/1 or /domains/1.json
def update
respond_to do |format|
if @domain.update(domain_params)
format.html { redirect_to domain_url(@domain), notice: "Domain was successfully updated." }
format.json { render :show, status: :ok, location: @domain }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @domain.errors, status: :unprocessable_entity }
end
end
end
# DELETE /domains/1 or /domains/1.json
def destroy
@domain.destroy
respond_to do |format|
format.html { redirect_to domains_url, notice: "Domain was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_domain
@domain = Domain.find(params[:id])
end
# Only allow a list of trusted parameters through.
def domain_params
params.require(:domain).permit(:domain)
end
end

View File

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

2
app/models/domain.rb Normal file
View File

@@ -0,0 +1,2 @@
class Domain < ApplicationRecord
end

View File

@@ -0,0 +1,7 @@
<div id="<%= dom_id domain %>">
<p>
<strong>Domain:</strong>
<%= domain.domain %>
</p>
</div>

View File

@@ -0,0 +1,2 @@
json.extract! domain, :id, :domain, :created_at, :updated_at
json.url domain_url(domain, format: :json)

View File

@@ -0,0 +1,22 @@
<%= form_with(model: domain) do |form| %>
<% if domain.errors.any? %>
<div style="color: red">
<h2><%= pluralize(domain.errors.count, "error") %> prohibited this domain from being saved:</h2>
<ul>
<% domain.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form.label :domain, style: "display: block" %>
<%= form.text_field :domain %>
</div>
<div>
<%= form.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,10 @@
<h1>Editing domain</h1>
<%= render "form", domain: @domain %>
<br>
<div>
<%= link_to "Show this domain", @domain %> |
<%= link_to "Back to domains", domains_path %>
</div>

View File

@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>
<h1>Domains</h1>
<div id="domains">
<% @domains.each do |domain| %>
<%= render domain %>
<p>
<%= link_to "Show this domain", domain %>
</p>
<% end %>
</div>
<%= link_to "New domain", new_domain_path %>

View File

@@ -0,0 +1 @@
json.array! @domains, partial: "domains/domain", as: :domain

View File

@@ -0,0 +1,9 @@
<h1>New domain</h1>
<%= render "form", domain: @domain %>
<br>
<div>
<%= link_to "Back to domains", domains_path %>
</div>

View File

@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>
<%= render @domain %>
<div>
<%= link_to "Edit this domain", edit_domain_path(@domain) %> |
<%= link_to "Back to domains", domains_path %>
<%= button_to "Destroy this domain", @domain, method: :delete %>
</div>

View File

@@ -0,0 +1 @@
json.partial! "domains/domain", domain: @domain