/ / Як надсилати гіперпосилання (URL завдання) в CSV-експорт - ruby-on-rails, ruby, csv, гіперпосилання

Як надіслати гіперпосилання (URL-адресу завдання) в CSV Export - рубіни на рейках, рубій, csv, гіперпосилання

Я хочу показати Task_Url у файлі CSV, я використав цей запит для CSV -

user_trackers = TaskTimeTracker.joins(:task).where("(task_time_trackers.created_at BETWEEN ? AND ?)",Date.current.beginning_of_month, Date.current.end_of_month )

@trackers = user_trackers

Це метод CSV, який я використав -

def export_csv
columns = %w(Date Task Task_URL TimeSpent Log)
CSV.generate do |csv|
csv << columns
@trackers.each do |t|
csv << [t.created_at,
t.task.name,

t.time_spent,
t.description ]
end
end
end

Це використовувана нами модель завдань.

class Task < ActiveRecord::Base
TASK_TYPES = { bug: "Bug", enhancement: "Enhancement", feature: "Feature"}
belongs_to :project
belongs_to :user
has_many :task_time_trackers, dependent: :nullify
validates :task_type,presence: true
end

Завдання_Time_Tracker Модель

class TaskTimeTracker < ActiveRecord::Base
belongs_to :task
belongs_to :user
validates :description,presence:true
validates :time_spent,presence:true
end

Інформація про схему Task_Time_Tracker

# == Schema Information
#
# Table name: task_time_trackers
#
#  id          :integer          not null, primary key
#  description :text(65535)
#  time_spent  :float(24)
#  created_at  :datetime         not null
#  updated_at  :datetime         not null
#  task_id     :integer
#  user_id     :integer

Модель проекту

class Project < ActiveRecord::Base
has_many :tasks, dependent: :destroy
has_and_belongs_to_many :users
end

Відповіді:

1 для відповіді № 1

Цей спосіб реалізований у контролері чи моделі?

Перевірте це:

def export_csv
columns = %w(Date Task Task_URL TimeSpent Log)
CSV.generate do |csv|
csv << columns
@trackers.each do |t|
csv << [t.created_at,
t.task.name,
task_url(t.task),
t.time_spent,
t.description ]
end
end
end

1 для відповіді № 2

Цей спосіб реалізований у контролері чи моделі?

Перевірте це:

def export_csv
columns = %w(Date Task Task_URL TimeSpent Log)
CSV.generate do |csv|
csv << columns
@trackers.each do |t|
csv << [t.created_at,
t.task.name,
task_url(t.task),
t.time_spent,
t.description ]
end
end
end