Skip to content

Commit

Permalink
Added validations, Added content in Home page
Browse files Browse the repository at this point in the history
  • Loading branch information
atchyut-re committed May 31, 2016
1 parent ac62e90 commit 3c01a83
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def update
end

def destroy
if @category.destroy
redirect_to categories_path
end
end

def index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/expenses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create
redirect_to expenses_path
flash[:success] = "New expence has been created"
else
render Expense.new
redirect_to new_expense_path
end
end

Expand Down
3 changes: 3 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Category < ActiveRecord::Base
belongs_to :user
has_many :expenses

validates :name , uniqueness: true
validates :name , presence: true
end
2 changes: 2 additions & 0 deletions app/models/expense.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Expense < ActiveRecord::Base
belongs_to :category
belongs_to :user

validates :amount, :category, :date, :description, presence: true
end
20 changes: 20 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@ class User < ActiveRecord::Base

has_many :categories
has_many :expenses, through: :categories

after_create :create_default_categories

DEFAULT_CATEGORIES = [
{name: 'Phone bill'},
{name: 'Entertainment'},
{name: 'Rent'},
{name: 'Travel'},
{name: 'Parties'},
{name: 'Gifts'},
{name: 'Phone bill'},
{name: 'Miscellaneous'}
]

def create_default_categories
DEFAULT_CATEGORIES.each do |default_attrs|
self.categories.build(default_attrs)
end
end

end
3 changes: 2 additions & 1 deletion app/views/expenses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@

<div class="form-group">
<%= f.label :category, "Category:" %><br>
<div class="col-md-2">
<div class="col-md-4">

<%= f.collection_select(:category_id, current_user.categories, :id, :name, {}, { :class => "select_box selectpicker picker"}) %>
<%= link_to "+ Add Category", new_category_path %>
</div>
</div>

Expand Down
14 changes: 13 additions & 1 deletion app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<h1> Expence Manager </h1>
<p>Manage all your expences with hassle free </p>

<div class="well">
<%= link_to "+ Add Expense", new_expense_path, class: "btn btn-small btn-success" %>
<%= link_to "+ Add Category", new_category_path, class: "btn btn-small btn-success" %>
</div>

<p>Manage all your expences with hassle free </p>
<h3>Benefits:</h3>
<ul>
<li>sorting the expenditures based on the categories.</li>
<li>sorting the expenditures based on the period of time.</li>
<li>Addition & deletion of personal categories.</li>
<li>Graph charts based on certain time periods.</li>
<li>Download all the expense list in the excel sheet</li>
</ul>

0 comments on commit 3c01a83

Please sign in to comment.