added the last two models

This commit is contained in:
2023-05-10 19:53:55 +01:00
parent f15f9be809
commit 05f803436e
21 changed files with 303 additions and 6 deletions

View File

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

View File

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

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

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

View File

@@ -0,0 +1,12 @@
<div id="<%= dom_id credential %>">
<p>
<strong>Email:</strong>
<%= credential.email %>
</p>
<p>
<strong>Password:</strong>
<%= credential.password %>
</p>
</div>

View File

@@ -0,0 +1,2 @@
json.extract! credential, :id, :email, :password, :created_at, :updated_at
json.url credential_url(credential, format: :json)

View File

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

View File

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

View File

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

View File

@@ -0,0 +1 @@
json.array! @credentials, partial: "credentials/credential", as: :credential

View File

@@ -0,0 +1,9 @@
<h1>New credential</h1>
<%= render "form", credential: @credential %>
<br>
<div>
<%= link_to "Back to credentials", credentials_path %>
</div>

View File

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

View File

@@ -0,0 +1 @@
json.partial! "credentials/credential", credential: @credential