Skip to content

Commit

Permalink
Modify user controller
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhamiid committed Oct 27, 2022
1 parent 66aa0bb commit c3ed448
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 33 deletions.
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class UsersController < ApplicationController

# GET /users or /users.json
def index
@users = User.all
@user = current_user
end

# GET /users/1 or /users/1.json
Expand All @@ -28,7 +28,7 @@ def create

# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
@user = current_user
end

# Only allow a list of trusted parameters through.
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
:recoverable, :rememberable, :validatable,
:confirmable

has_many :entities
has_many :groups
Expand Down
18 changes: 0 additions & 18 deletions app/views/entities/_entity.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
<div id="<%= dom_id entity %>" class="d-flex justify-content-around" >
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Amount $</th>
</tr>
</thead>
<tbody>
<% @group.entities.each do |entity| %>
<tr>
<td><%= entity.name %></td>
<td>$<%= entity.amount %>.00</td>
</tr>
<% end %>
</tbody>
</table>
</div>
4 changes: 2 additions & 2 deletions app/views/groups/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<h3><%= entity.name %></h3>
<p><i class="bi bi-calendar3 me-2"></i><%= entity.created_at.strftime("%Y-%m-%d") %>
<p>TOTAL PAYMENT:<span class="text-dark fw-bold"> $<%= entity.amount %>.00</span></p>
<p><%= button_to "Delete", group_entity_path(@group, entity), method: :delete, class: "btn btn-danger" %></p>
<p><%= button_to "Delete", group_entity_path(@group, entity), method: :delete, class: "btn btn-danger btn-sm" %></p>
</div>
<% end %>
<% end %>
</div>
</div>
<div>

<div class="p-2 mt-5 bg-success">
<%= link_to "Add a new transaction", new_group_entity_path(@group), class: "d-block p-2 bg-success text-white text-white text-decoration-none text-center border border-white rounded-1" %>
</div>
Expand Down
7 changes: 1 addition & 6 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
<h1>Users</h1>

<div id="users">
<% @users.each do |user| %>
<%= render user %>
<p>
<%= link_to "Show this user", user %>
</p>
<% end %>
<%= @user.name %>
</div>

8 changes: 4 additions & 4 deletions db/migrate/20221023132417_add_devise_to_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def self.up
# t.string :last_sign_in_ip

## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable

## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
Expand Down
4 changes: 4 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3ed448

Please sign in to comment.