Slowly getting the nested controllers working
More tests required
This commit is contained in:
parent
b76375d086
commit
1eb8c2753f
@ -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"}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
class Virtual < ApplicationRecord
|
||||
belongs_to :domain
|
||||
validate :domain_name_exists
|
||||
validates :email, presence: true
|
||||
validates :destination, presence: true
|
||||
|
||||
@ -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 %>
|
||||
|
||||
@ -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>
|
||||
|
||||
2
test/fixtures/virtuals.yml
vendored
2
test/fixtures/virtuals.yml
vendored
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user