added the last two models
This commit is contained in:
70
app/controllers/credentials_controller.rb
Normal file
70
app/controllers/credentials_controller.rb
Normal 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
|
||||
2
app/helpers/credentials_helper.rb
Normal file
2
app/helpers/credentials_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CredentialsHelper
|
||||
end
|
||||
2
app/models/credential.rb
Normal file
2
app/models/credential.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Credential < ApplicationRecord
|
||||
end
|
||||
12
app/views/credentials/_credential.html.erb
Normal file
12
app/views/credentials/_credential.html.erb
Normal 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>
|
||||
2
app/views/credentials/_credential.json.jbuilder
Normal file
2
app/views/credentials/_credential.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.extract! credential, :id, :email, :password, :created_at, :updated_at
|
||||
json.url credential_url(credential, format: :json)
|
||||
27
app/views/credentials/_form.html.erb
Normal file
27
app/views/credentials/_form.html.erb
Normal 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 %>
|
||||
10
app/views/credentials/edit.html.erb
Normal file
10
app/views/credentials/edit.html.erb
Normal 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>
|
||||
14
app/views/credentials/index.html.erb
Normal file
14
app/views/credentials/index.html.erb
Normal 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 %>
|
||||
1
app/views/credentials/index.json.jbuilder
Normal file
1
app/views/credentials/index.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.array! @credentials, partial: "credentials/credential", as: :credential
|
||||
9
app/views/credentials/new.html.erb
Normal file
9
app/views/credentials/new.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<h1>New credential</h1>
|
||||
|
||||
<%= render "form", credential: @credential %>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<%= link_to "Back to credentials", credentials_path %>
|
||||
</div>
|
||||
10
app/views/credentials/show.html.erb
Normal file
10
app/views/credentials/show.html.erb
Normal 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>
|
||||
1
app/views/credentials/show.json.jbuilder
Normal file
1
app/views/credentials/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! "credentials/credential", credential: @credential
|
||||
Reference in New Issue
Block a user