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
|
class Credential < ApplicationRecord
|
||||||
|
belongs_to :domain
|
||||||
validates :email, presence: true
|
validates :email, presence: true
|
||||||
validates :email, uniqueness: true
|
validates :email, uniqueness: 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"}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
class Domain < ApplicationRecord
|
class Domain < ApplicationRecord
|
||||||
|
has_many :credentials, dependent: :destroy
|
||||||
|
has_many :virtuals, dependent: :destroy
|
||||||
validates :domain, presence: true
|
validates :domain, presence: true
|
||||||
validates :domain, uniqueness: true
|
validates :domain, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class Virtual < ApplicationRecord
|
class Virtual < ApplicationRecord
|
||||||
|
belongs_to :domain
|
||||||
validate :domain_name_exists
|
validate :domain_name_exists
|
||||||
validates :email, presence: true
|
validates :email, presence: true
|
||||||
validates :destination, presence: true
|
validates :destination, presence: true
|
||||||
|
|||||||
@ -3,12 +3,11 @@
|
|||||||
<h1>Domains</h1>
|
<h1>Domains</h1>
|
||||||
|
|
||||||
<div id="domains">
|
<div id="domains">
|
||||||
|
<ul>
|
||||||
<% @domains.each do |domain| %>
|
<% @domains.each do |domain| %>
|
||||||
<%= render domain %>
|
<li><%= link_to domain.domain, domain %></li>
|
||||||
<p>
|
|
||||||
<%= link_to "Show this domain", domain %>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= link_to "New domain", new_domain_path %>
|
<%= link_to "New domain", new_domain_path %>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
<p style="color: green"><%= notice %></p>
|
<p style="color: green"><%= notice %></p>
|
||||||
|
<h1><%= @domain.domain %></h1>
|
||||||
<%= render @domain %>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= link_to "Edit this domain", edit_domain_path(@domain) %> |
|
<%= link_to "Edit this domain", edit_domain_path(@domain) %> |
|
||||||
@ -8,3 +7,19 @@
|
|||||||
|
|
||||||
<%= button_to "Destroy this domain", @domain, method: :delete %>
|
<%= button_to "Destroy this domain", @domain, method: :delete %>
|
||||||
</div>
|
</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
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
one:
|
one:
|
||||||
|
domain: one
|
||||||
email: abuse@example.net
|
email: abuse@example.net
|
||||||
destination: bob@example.net
|
destination: bob@example.net
|
||||||
|
|
||||||
two:
|
two:
|
||||||
|
domain: one
|
||||||
email: postmaster@example.net
|
email: postmaster@example.net
|
||||||
destination: bob@example.net
|
destination: bob@example.net
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user