Skip to content

Commit

Permalink
worked on the validation
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrobert committed Jun 23, 2020
1 parent c85d448 commit 5d72ec4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,9 @@ form textarea {

.cd{
margin-top: 10px;
}

.error{
font-size: 18px;
color: red;
}
3 changes: 3 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Group < ApplicationRecord
belongs_to :user
has_many :transactions

validates :name, presence: true, length: { maximum: 20 }
validates :icon, presence: true
end
7 changes: 7 additions & 0 deletions app/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ class Transaction < ApplicationRecord
belongs_to :user
belongs_to :group, optional: true

validates :name, presence: true, length: { maximum: 20 }
validates :amount, presence: true, numericality: { less_than_or_equal_to: 100_000, greater_than: 1 }





end
8 changes: 8 additions & 0 deletions app/views/groups/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<%= form_for @group do |f| %>

<% if @group.errors.any? %>
<ul>
<% @group.errors.full_messages.each do |msg| %>
<li class="error"><%= msg %></li>
<% end %>
</ul>
<% end %>
<%= f.label :name %><br />
<%= f.text_field :name %><br />

Expand Down
10 changes: 10 additions & 0 deletions app/views/transactions/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<%= form_for @transaction do |f| %>

<% if @transaction.errors.any? %>
<ul>
<% @transaction.errors.full_messages.each do |msg| %>
<li class="error"><%= msg %></li>
<% end %>
</ul>
<% end %>


<%= f.label :name %><br />
<%= f.text_field :name %><br />

Expand Down

0 comments on commit 5d72ec4

Please sign in to comment.