From 103647e8434135f21e36bb285f1de3280d2c2fa2 Mon Sep 17 00:00:00 2001 From: peterrobert Date: Tue, 23 Jun 2020 18:35:35 +0300 Subject: [PATCH] removed the delete buttons for none members --- app/assets/stylesheets/application.scss | 4 ++++ app/helpers/groups_helper.rb | 14 +++++++++++++- app/views/groups/index.html.erb | 7 +++---- app/views/groups/show.html.erb | 10 ++++++---- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index be418d7..d315721 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -292,4 +292,8 @@ form textarea { font-size: 20px; font-weight: bold; color: grey; +} + +.hidden{ + display: none; } \ No newline at end of file diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index e7fefa5..9984171 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -1,3 +1,15 @@ module GroupsHelper - + def edit_delete_btn(user, group) + + if group.user_id == user.id + links = [link_to("edit", edit_group_path(group), class: "btn btn-primary edit_btn"), link_to("delete", group_path(group), class: "btn btn-danger delete_grp_btn", data: {confirm: "Are you sure?"}, method: :delete)] + + content_tag (:span) do + links.collect{ + |l| concat content_tag(:span, l) + } + end + end + + end end diff --git a/app/views/groups/index.html.erb b/app/views/groups/index.html.erb index e9138a7..c518783 100644 --- a/app/views/groups/index.html.erb +++ b/app/views/groups/index.html.erb @@ -36,10 +36,9 @@ Groups
<%= g.name %>

<%= g.created_at %>

- - <%= link_to "edit", edit_group_path(g), :class => "btn btn-primary edit_btn" %> - - <%= link_to "delete", group_path(g), :class => "btn btn-danger delete_grp_btn", data: {confirm: "Are you sure?"}, :method => :delete %> + <%= edit_delete_btn(current_user, g) %> + + diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb index 102b1fd..6eb21df 100644 --- a/app/views/groups/show.html.erb +++ b/app/views/groups/show.html.erb @@ -1,10 +1,12 @@
- +<%= link_to root_path do %> + +<% end %>
-Transactions +Transactions for a specific group
-
<%= t.name %>
-

$ <%= t.amount %>

+
<%= t.name %>
+

$ <%= t.amount %>

created by <%= t.user.name %>

<%= t.created_at %>