From 81c9e7db107ee549c26010ac14cd8aa106640415 Mon Sep 17 00:00:00 2001 From: Mohamad Abras Date: Sat, 17 Apr 2021 21:35:52 +0300 Subject: [PATCH] use rails action_name & controller_name methods (#2666) Co-authored-by: Ahmad Farhat --- app/helpers/application_helper.rb | 11 ++--------- app/views/admins/components/_menu_buttons.html.erb | 14 +++++++------- app/views/layouts/application.html.erb | 2 +- app/views/shared/_header.html.erb | 2 +- app/views/users/components/_menu_buttons.html.erb | 6 +++--- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 57d683f3..238cddf3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -58,18 +58,11 @@ module ApplicationHelper # Returns 'active' if the current page is the users home page (used to style header) def active_home home_actions = %w[show cant_create_rooms] - return "active" if params[:controller] == "admins" && params[:action] == "index" && current_user.has_role?(:super_admin) - return "active" if params[:controller] == "rooms" && home_actions.include?(params[:action]) + return "active" if controller_name == "admins" && action_name == "index" && current_user.has_role?(:super_admin) + return "active" if controller_name == "rooms" && home_actions.include?(action_name) "" end - # Returns the action method of the current page - def active_page - route = Rails.application.routes.recognize_path(request.env['PATH_INFO']) - - route[:action] - end - def role_colour(role) role.colour || Rails.configuration.primary_color_default end diff --git a/app/views/admins/components/_menu_buttons.html.erb b/app/views/admins/components/_menu_buttons.html.erb index 7387e97c..d4c0e4dd 100644 --- a/app/views/admins/components/_menu_buttons.html.erb +++ b/app/views/admins/components/_menu_buttons.html.erb @@ -17,29 +17,29 @@ <% highest_role = current_user.role %> <% highest_role.name %> <% if highest_role.get_permission("can_manage_users") || highest_role.name == "super_admin" %> - <%= link_to admins_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "index"}" do %> + <%= link_to admins_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "index"}" do %> <%= t("administrator.users.title") %> <% end %> <% end %> <% if highest_role.get_permission("can_manage_rooms_recordings") || highest_role.name == "super_admin" %> - <%= link_to admin_rooms_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "server_rooms"}" do %> + <%= link_to admin_rooms_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "server_rooms"}" do %> <%= t("administrator.rooms.title") %> <% end %> - <%= link_to admin_recordings_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "server_recordings"}" do %> + <%= link_to admin_recordings_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "server_recordings"}" do %> <%= t("administrator.recordings.title") %> <% end %> <% end %> <% if highest_role.get_permission("can_edit_site_settings") || highest_role.name == "super_admin" %> - <%= link_to admin_site_settings_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "site_settings"}" do %> + <%= link_to admin_site_settings_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "site_settings"}" do %> <%= t("administrator.site_settings.title") %> <% end %> - <%= link_to admin_room_configuration_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "room_configuration"}" do %> + <%= link_to admin_room_configuration_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "room_configuration"}" do %> <%= t("administrator.room_configuration.title") %> <% end %> <% end %> <% if highest_role.get_permission("can_edit_roles") || highest_role.name == "super_admin" %> - <%= link_to admin_roles_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "roles"}" do %> + <%= link_to admin_roles_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "roles"}" do %> <%= t("administrator.roles.title") %> <% end %> <% end %> - + \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 520ec36c..bc207516 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -59,7 +59,7 @@ - "> + "> <%= render "shared/header" %>
diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 21ffaaf8..c0c6a01f 100755 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -32,7 +32,7 @@ <% end %> <% if current_user.role.get_permission("can_create_rooms") && !current_user.has_role?(:super_admin) && !hide_recording_tables %> - <% all_rec_page = params[:controller] == "users" && params[:action] == "recordings" ? "active" : "" %> + <% all_rec_page = controller_name == "users" && action_name == "recordings" ? "active" : "" %> <%= link_to get_user_recordings_path(current_user), class: "px-3 mx-1 mt-1 header-nav #{all_rec_page}" do %> <%= t("header.all_recordings") %> <% end %> diff --git a/app/views/users/components/_menu_buttons.html.erb b/app/views/users/components/_menu_buttons.html.erb index d6c3e266..561884ac 100644 --- a/app/views/users/components/_menu_buttons.html.erb +++ b/app/views/users/components/_menu_buttons.html.erb @@ -14,15 +14,15 @@ %>
- <%= link_to edit_user_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "edit"}" do %> + <%= link_to edit_user_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "edit"}" do %> <%= t("settings.account.title") %> <% end %> <% if current_user.greenlight_account? %> - <%= link_to change_password_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "change_password"}" do %> + <%= link_to change_password_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "change_password"}" do %> <%= t("settings.password.title") %> <% end %> <% end %> - <%= link_to delete_account_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if active_page == "delete_account"}" do %> + <%= link_to delete_account_path, class: "list-group-item list-group-item-action dropdown-item #{"active" if action_name == "delete_account"}" do %> <%= t("settings.delete.title") %> <% end %>
\ No newline at end of file