Projects selector
This commit is contained in:
@@ -1,5 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
include Authentication
|
||||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
||||
allow_browser versions: :modern
|
||||
|
||||
helper_method :all_projects, :current_project
|
||||
|
||||
private
|
||||
|
||||
# Needed in projects selector (and can be used anywhere else)
|
||||
def all_projects
|
||||
Project.order(:name)
|
||||
end
|
||||
|
||||
attr_accessor :current_project
|
||||
end
|
||||
|
||||
@@ -38,6 +38,7 @@ class ProjectsController < ApplicationController
|
||||
|
||||
def fetch_project!
|
||||
@project = Project.find_by!(code: params[:id])
|
||||
self.current_project = @project
|
||||
end
|
||||
|
||||
def project_params
|
||||
|
||||
@@ -4,9 +4,9 @@ class TasksController < ApplicationController
|
||||
before_action :fetch_task, only: %w[show edit update delete]
|
||||
|
||||
def index
|
||||
@project = fetch_project
|
||||
@tasks = if @project
|
||||
@project.tasks
|
||||
self.current_project = fetch_project
|
||||
@tasks = if current_project
|
||||
current_project.tasks
|
||||
else
|
||||
Task.all
|
||||
end
|
||||
@@ -58,5 +58,6 @@ class TasksController < ApplicationController
|
||||
|
||||
def fetch_task
|
||||
@task = Task.includes(:project).find_by_full_number_or_id!(params[:id])
|
||||
self.current_project = @task.project
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user