diff --git a/PROJECT_JOURNAL.md b/PROJECT_JOURNAL.md index efeb710..573271a 100644 --- a/PROJECT_JOURNAL.md +++ b/PROJECT_JOURNAL.md @@ -760,4 +760,45 @@ I updated the groups index page to first check if there are any groups. If there <% 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 +

<%= group.movements.sum(:amount) %>

+``` +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 +
+ <%= link_to "Go back", authenticated_root_path %> + <%= image_tag("group_icons/#{@group.icon}", alt: @group.icon, class: "icon-preview") %> +

<%= @group.name %> movements

+ <% if @movements.empty? %> +

There are no movements, yet.

+ <% else %> + <%= @movements.sum(:amount)%> +
+ <%= @movements.each do |movement| %> + + <% end %> +
+ <% end %> + <%= link_to "Add a new movement", new_user_group_movement_path(current_user, @group) %> +
+``` + +I added a "Go back" button for the Group new view: + +```erb + <%= link_to "Go back", authenticated_root_path%> ``` \ No newline at end of file diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index ecf8f34..2dcff2b 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/app/views/groups/index.html.erb b/app/views/groups/index.html.erb index 2a7df6d..69f00d5 100644 --- a/app/views/groups/index.html.erb +++ b/app/views/groups/index.html.erb @@ -12,7 +12,7 @@ <%= image_tag("group_icons/#{group.icon}", alt: group.name, class: "icon-preview") %>

<%= group.created_at %>

<%= group.name %>

-

<%= "Change later for real total amount in dollars" %>

+

<%= group.movements.sum(:amount) %>

<% end %> <%= button_to "Delete", user_group_path(current_user, group), method: :delete %> diff --git a/app/views/groups/new.html.erb b/app/views/groups/new.html.erb index 42a7403..bbd3a34 100644 --- a/app/views/groups/new.html.erb +++ b/app/views/groups/new.html.erb @@ -16,4 +16,5 @@ <%= form.submit "Create group" %> + <%= link_to "Go back", authenticated_root_path%> <% end %> \ No newline at end of file diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb index 667157d..bd5f27e 100644 --- a/app/views/groups/show.html.erb +++ b/app/views/groups/show.html.erb @@ -1,2 +1,16 @@ -

Groups#show

-

Find me in app/views/groups/show.html.erb

+
+ <%= link_to "Go back", authenticated_root_path %> + <%= image_tag("group_icons/#{@group.icon}", alt: @group.icon, class: "icon-preview") %> +

<%= @group.name %> movements

+ <% if @movements.empty? %> +

There are no movements, yet.

+ <% else %> + <%= @movements.sum(:amount)%> +
+ <%= @movements.each do |movement| %> + + <% end %> +
+ <% end %> + <%= link_to "Add a new movement", new_user_group_movement_path(current_user, @group) %> +