Slowly getting the nested controllers working

More tests required
This commit is contained in:
Jez Caudle 2023-06-21 09:31:20 +01:00
parent b76375d086
commit 1eb8c2753f
6 changed files with 26 additions and 6 deletions

View File

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

View File

@ -1,4 +1,6 @@
class Domain < ApplicationRecord
has_many :credentials, dependent: :destroy
has_many :virtuals, dependent: :destroy
validates :domain, presence: true
validates :domain, uniqueness: true
end

View File

@ -1,4 +1,5 @@
class Virtual < ApplicationRecord
belongs_to :domain
validate :domain_name_exists
validates :email, presence: true
validates :destination, presence: true

View File

@ -3,12 +3,11 @@
<h1>Domains</h1>
<div id="domains">
<ul>
<% @domains.each do |domain| %>
<%= render domain %>
<p>
<%= link_to "Show this domain", domain %>
</p>
<li><%= link_to domain.domain, domain %></li>
<% end %>
</ul>
</div>
<%= link_to "New domain", new_domain_path %>

View File

@ -1,6 +1,5 @@
<p style="color: green"><%= notice %></p>
<%= render @domain %>
<h1><%= @domain.domain %></h1>
<div>
<%= link_to "Edit this domain", edit_domain_path(@domain) %> |
@ -8,3 +7,19 @@
<%= button_to "Destroy this domain", @domain, method: :delete %>
</div>
<h2>Credentials (<%= @domain.credentials.count %>)</h2>
<ul>
<li><%= link_to "Add #{@domain.domain} email address", new_domain_credential_path(@domain) %>
<% @domain.credentials.each do |credential| %>
<li><%= credential.email %></li>
<% end %>
</ul>
<h2>Virtuals (<%= @domain.virtuals.count %>)</h2>
<ul>
<li><%= link_to "Add #{@domain.domain} virtual email", new_domain_virtual_path(@domain) %></li>
<% @domain.virtuals.each do |virtual| %>
<li><%= virtual.email%> >> <%= virtual.destination%></li>
<% end %>
</ul>

View File

@ -1,9 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
domain: one
email: abuse@example.net
destination: bob@example.net
two:
domain: one
email: postmaster@example.net
destination: bob@example.net