diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bbd6ab229..c7444a5d5 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -29,13 +29,19 @@ class ProjectsController < ApplicationController .find_by_id(params[:organization])) end - @current_organization_id = current_organization.id - @current_sort = params[:sort].to_s - @projects_by_orgs = current_user.projects_by_orgs(@current_organization_id, - @current_sort, - @filter_by_archived) + if current_user.organizations.any? + @current_organization_id = current_organization.id + @organization_projects = current_organization.active_project + @current_sort = params[:sort].to_s + @projects_by_orgs = current_user + .projects_by_orgs(@current_organization_id, + @current_sort, + @filter_by_archived) + end + @organizations = current_user.organizations + # New project for create new project modal @project = Project.new end diff --git a/app/models/organization.rb b/app/models/organization.rb index d49e49521..3b4489174 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -305,4 +305,8 @@ class Organization < ActiveRecord::Base def protocol_keywords_list ProtocolKeyword.where(organization: self).pluck(:name) end + + def active_project + projects.where(archived: false) + end end diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index e376decd4..b706c5212 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -111,12 +111,11 @@ <% else %> -<% end %> - -<% if current_organization.projects.length > 0 %> - <%= render partial: "projects/index/org_projects", - locals: { org: current_organization, - projects: current_organization.projects } %> + <% if @organization_projects.any? %> + <%= render partial: "projects/index/org_projects", + locals: { org: current_organization, + projects: @organization_projects } %> + <% end %> <% end %> <%= javascript_include_tag "projects/index", "data-turbolinks-track" => true %>