Something not right here with Kate.

This commit is contained in:
Jez Caudle 2023-06-21 11:07:34 +01:00
parent 1eb8c2753f
commit d882c1a521
6 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,6 @@
class CredentialsController < ApplicationController class CredentialsController < ApplicationController
before_action :set_credential, only: %i[ show edit update destroy ] before_action :set_credential, only: %i[ show edit update destroy ]
before_action :set_domain, only: %i[ new ]
# GET /credentials or /credentials.json # GET /credentials or /credentials.json
def index def index
@ -63,6 +64,10 @@ class CredentialsController < ApplicationController
@credential = Credential.find(params[:id]) @credential = Credential.find(params[:id])
end end
def set_domain
@domain = Domain.find(params[:domain_id])
end
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def credential_params def credential_params
params.require(:credential).permit(:email, :password) params.require(:credential).permit(:email, :password)

View File

@ -2,5 +2,6 @@ class Credential < ApplicationRecord
belongs_to :domain belongs_to :domain
validates :email, presence: true validates :email, presence: true
validates :email, uniqueness: true validates :email, uniqueness: true
validates :domain_id, presence: true
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"} validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"}
end end

View File

@ -3,6 +3,7 @@ class Virtual < ApplicationRecord
validate :domain_name_exists validate :domain_name_exists
validates :email, presence: true validates :email, presence: true
validates :destination, presence: true validates :destination, presence: true
validates :domain_id, presence: true
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"} validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "email must be valid"}
validates :destination, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "destination must be valid"} validates :destination, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i , message: "destination must be valid"}
validates :destination, uniqueness: {scope: :email, message: "a redirection pair must be unique"} validates :destination, uniqueness: {scope: :email, message: "a redirection pair must be unique"}

View File

@ -1,4 +1,4 @@
<%= form_with(model: credential) do |form| %> <%= form_with(model: [@domain, credential]) do |form| %>
<% if credential.errors.any? %> <% if credential.errors.any? %>
<div style="color: red"> <div style="color: red">
<h2><%= pluralize(credential.errors.count, "error") %> prohibited this credential from being saved:</h2> <h2><%= pluralize(credential.errors.count, "error") %> prohibited this credential from being saved:</h2>

View File

@ -5,5 +5,5 @@
<br> <br>
<div> <div>
<%= link_to "Back to credentials", credentials_path %> <%= link_to "Back to the domain", domain_path(@domain) %>
</div> </div>

View File

@ -2,10 +2,7 @@
<h1><%= @domain.domain %></h1> <h1><%= @domain.domain %></h1>
<div> <div>
<%= link_to "Edit this domain", edit_domain_path(@domain) %> | <%= link_to "Edit this domain", edit_domain_path(@domain) %> | <%= link_to "Back to domains", domains_path %> | <%= button_to "Destroy this domain", @domain, method: :delete %>
<%= link_to "Back to domains", domains_path %>
<%= button_to "Destroy this domain", @domain, method: :delete %>
</div> </div>
<h2>Credentials (<%= @domain.credentials.count %>)</h2> <h2>Credentials (<%= @domain.credentials.count %>)</h2>