entity scaffold
This commit is contained in:
58
app/controllers/entities_controller.rb
Normal file
58
app/controllers/entities_controller.rb
Normal file
@ -0,0 +1,58 @@
|
||||
class EntitiesController < ApplicationController
|
||||
before_action :set_entity, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /entities
|
||||
def index
|
||||
@entities = Entity.all
|
||||
end
|
||||
|
||||
# GET /entities/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /entities/new
|
||||
def new
|
||||
@entity = Entity.new
|
||||
end
|
||||
|
||||
# GET /entities/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /entities
|
||||
def create
|
||||
@entity = Entity.new(entity_params)
|
||||
|
||||
if @entity.save
|
||||
redirect_to @entity, notice: "Entity was successfully created."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /entities/1
|
||||
def update
|
||||
if @entity.update(entity_params)
|
||||
redirect_to @entity, notice: "Entity was successfully updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /entities/1
|
||||
def destroy
|
||||
@entity.destroy
|
||||
redirect_to entities_url, notice: "Entity was successfully destroyed."
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_entity
|
||||
@entity = Entity.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def entity_params
|
||||
params.require(:entity).permit(:name, :ha_id, :type , :member_id)
|
||||
end
|
||||
end
|
2
app/helpers/entities_helper.rb
Normal file
2
app/helpers/entities_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module EntitiesHelper
|
||||
end
|
7
app/models/entity.rb
Normal file
7
app/models/entity.rb
Normal file
@ -0,0 +1,7 @@
|
||||
class Entity < ApplicationRecord
|
||||
validate :name , presence: true
|
||||
validate :ha_id , presence: true
|
||||
validate :type , presence: true
|
||||
validate :member_id , presence: true
|
||||
|
||||
end
|
19
app/views/entities/_form.html.haml
Normal file
19
app/views/entities/_form.html.haml
Normal file
@ -0,0 +1,19 @@
|
||||
= form_for @entity do |f|
|
||||
- if @entity.errors.any?
|
||||
#error_explanation
|
||||
%h2= "#{pluralize(@entity.errors.count, "error")} prohibited this entity from being saved:"
|
||||
%ul
|
||||
- @entity.errors.full_messages.each do |message|
|
||||
%li= message
|
||||
|
||||
.field
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
.field
|
||||
= f.label :ha_id
|
||||
= f.text_field :ha_id
|
||||
.field
|
||||
= f.label :type
|
||||
= f.text_field :type
|
||||
.actions
|
||||
= f.submit 'Save'
|
7
app/views/entities/edit.html.haml
Normal file
7
app/views/entities/edit.html.haml
Normal file
@ -0,0 +1,7 @@
|
||||
%h1 Editing entity
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Show', @entity
|
||||
\|
|
||||
= link_to 'Back', entities_path
|
25
app/views/entities/index.html.haml
Normal file
25
app/views/entities/index.html.haml
Normal file
@ -0,0 +1,25 @@
|
||||
%h1 Listing entities
|
||||
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%th Ha
|
||||
%th Type
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
|
||||
%tbody
|
||||
- @entities.each do |entity|
|
||||
%tr
|
||||
%td= entity.name
|
||||
%td= entity.ha_id
|
||||
%td= entity.type
|
||||
%td= link_to 'Show', entity
|
||||
%td= link_to 'Edit', edit_entity_path(entity)
|
||||
%td= link_to 'Destroy', entity, method: :delete, data: { confirm: 'Are you sure?' }
|
||||
|
||||
%br
|
||||
|
||||
= link_to 'New Entity', new_entity_path
|
5
app/views/entities/new.html.haml
Normal file
5
app/views/entities/new.html.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%h1 New entity
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', entities_path
|
15
app/views/entities/show.html.haml
Normal file
15
app/views/entities/show.html.haml
Normal file
@ -0,0 +1,15 @@
|
||||
%p#notice= notice
|
||||
|
||||
%p
|
||||
%b Name:
|
||||
= @entity.name
|
||||
%p
|
||||
%b Ha:
|
||||
= @entity.ha_id
|
||||
%p
|
||||
%b Type:
|
||||
= @entity.type
|
||||
|
||||
= link_to 'Edit', edit_entity_path(@entity)
|
||||
\|
|
||||
= link_to 'Back', entities_path
|
Reference in New Issue
Block a user