Bugfix: Allow time log outside of project context

Fixes an issue where opening the log time page at the top-level causes
errors due to expecting a project to be set.

Refs #2804
This commit is contained in:
Trevor Vallender 2024-01-17 18:49:05 +00:00
parent 472d2b0479
commit 61ce2d0901
2 changed files with 7 additions and 2 deletions

View File

@ -13,7 +13,7 @@ class Job < ActiveRecord::Base
has_many :time_budgets, dependent: :destroy
accepts_nested_attributes_for :time_budgets, allow_destroy: true
scope :project_or_parent, ->(project) { where(project_id: [project.id, project.parent&.id]) }
scope :project_or_parent, ->(project) { where(project_id: [project&.id, project&.parent&.id]) }
scope :active, -> { where(starts_on: ..Date.today, ends_on: Date.today..) }
def with_all_time_budgets

View File

@ -1,3 +1,8 @@
<p>
<%= form.label :job_id %>
<% if @project.nil? %>
<%= form.collection_select :job_id, Job.active, :id, :name, include_blank: true %>
<% else %>
<%= form.collection_select :job_id, Job.active.project_or_parent(@project), :id, :name, include_blank: true %>
<% end %>
</p>