I moved a lot of the loading/logic from my view to my controller, and it's working great but after I did this I now have several very similar helper methods in my controller.
What is a more efficient way of doing this? Is there? I assume get_last_task_owed
and get_first_task_owed
I would be able to do in the view by finding the .first
and .last
of the record respectively.
def get_projects_owed
current_user.projects.where('end_date > ?', Date.today).order(:start_date).pluck(:name, :start_date, :end_date)
end
def get_all_projects
current_user.projects.order(:start_date).pluck(:name, :start_date, :end_date)
end
def get_all_tasks
@project.tasks.order(:product, :task_start_date).pluck(:product, :task_name, :task_start_date, :task_end_date).to_json
end
def get_last_task_owed
tasks = @project.tasks
tasks.where('task_end_date >= ?', Date.today).order('task_end_date DESC').first.task_end_date.strftime("%B %d, %Y")
end
def get_first_task_owed
tasks = @project.tasks
tasks.where('task_end_date >= ?', Date.today).order('task_end_date ASC').first.task_end_date.strftime("%B %d, %Y")
end
helper_method :get_projects_owed
helper_method :get_all_projects
helper_method :get_clients_with_projects
helper_method :get_all_tasks
helper_method :get_last_task_owed
helper_method :get_first_task_owed