diff --git a/app/models/job.rb b/app/models/job.rb index deadf3f..8229bf2 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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 diff --git a/app/views/time_entries/_edit_form_bottom.html.erb b/app/views/time_entries/_edit_form_bottom.html.erb index 99b5d12..d41cdcd 100644 --- a/app/views/time_entries/_edit_form_bottom.html.erb +++ b/app/views/time_entries/_edit_form_bottom.html.erb @@ -1,3 +1,8 @@

<%= form.label :job_id %> -<%= form.collection_select :job_id, Job.active.project_or_parent(@project), :id, :name, include_blank: true %> +<% 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 %> +