Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def export_to_csv
- @project = Project.find(params[:id])
- respond_to do |format|
- format.csv do
- @csv_string = FasterCSV.generate(:col_sep => ";") do |csv| # calling method from gem FasterCSV
- # header row for Project
- csv << ["id", "name", "description", "budget", "added_on", "current_status"]
- # data rows for Project
- csv << [@project.id, @project.name, @project.description,
- @project.budget, @project.added_on, @project.current_status]
- csv << [] # empty line
- # header rows for task that belongs to Project
- csv << ["id", "priority", "project.id", "title", "description",
- "assigned_user", "completed", "created_at", "updated_at"]
- @project.tasks.each do |task|
- # data rows for task Project
- csv << [task.id, task.priority, task.project.id, task.title, task.description,
- task.assigned_user, task.completed, task.created_at, task.updated_at]
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment