Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

06 transactions page #20

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions PROJECT_JOURNAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,45 @@ I updated the groups index page to first check if there are any groups. If there
</div>
<% end %>
<% end %>
```

I refined the group's show action in the controller to retrieve the specific group associated with the current user and to display its movements ordered from the most recent:

```ruby
def show
@group = current_user.groups.find(params[:id])
@movements = @group.movements.order(created_at: :desc)
end
```

In the groups index view, I added functionality to display the total sum of the transactions for each group:

```erb
<p><%= group.movements.sum(:amount) %></p>
```
For the group show view, I enhanced the usability and presentation. A 'Go back' button was implemented to provide easy navigation back to the home page. The group's associated icon and name are prominently displayed. Additionally, if there are movements, the total sum of the transactions is shown. I also prepared an iteration structure for future development, where each movement will be displayed. Finally, a link was added for creating new movements, anticipating the next development phase:

```erb
<div>
<%= link_to "Go back", authenticated_root_path %>
<%= image_tag("group_icons/#{@group.icon}", alt: @group.icon, class: "icon-preview") %>
<h1><%= @group.name %> movements </h1>
<% if @movements.empty? %>
<p>There are no movements, yet.</p>
<% else %>
<%= @movements.sum(:amount)%>
<div>
<%= @movements.each do |movement| %>
<!-- Display each movement here -->
<% end %>
</div>
<% end %>
<%= link_to "Add a new movement", new_user_group_movement_path(current_user, @group) %>
</div>
```

I added a "Go back" button for the Group new view:

```erb
<%= link_to "Go back", authenticated_root_path%>
```
5 changes: 4 additions & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ def index
@groups = Group.all
end

def show; end
def show
@group = current_user.groups.find(params[:id])
@movements = @group.movements.order(created_at: :desc)
end

def new
@group = current_user.groups.build
Expand Down
2 changes: 1 addition & 1 deletion app/views/groups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= image_tag("group_icons/#{group.icon}", alt: group.name, class: "icon-preview") %>
<p><%= group.created_at %></p>
<p><%= group.name %></p>
<p><%= "Change later for real total amount in dollars" %></p>
<p><%= group.movements.sum(:amount) %></p>
<% end %>
<%= button_to "Delete", user_group_path(current_user, group), method: :delete %>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/groups/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
</div>

<%= form.submit "Create group" %>
<%= link_to "Go back", authenticated_root_path%>
<% end %>
18 changes: 16 additions & 2 deletions app/views/groups/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
<h1>Groups#show</h1>
<p>Find me in app/views/groups/show.html.erb</p>
<div>
<%= link_to "Go back", authenticated_root_path %>
<%= image_tag("group_icons/#{@group.icon}", alt: @group.icon, class: "icon-preview") %>
<h1><%= @group.name %> movements </h1>
<% if @movements.empty? %>
<p>There are no movements, yet.</p>
<% else %>
<%= @movements.sum(:amount)%>
<div>
<%= @movements.each do |movement| %>
<!-- Display each movement here -->
<% end %>
</div>
<% end %>
<%= link_to "Add a new movement", new_user_group_movement_path(current_user, @group) %>
</div>
Loading