Add export functionality

This commit is contained in:
Petko Bordjukov 2015-10-13 14:34:45 +03:00
parent e997f1d042
commit db36fa09c6
5 changed files with 14 additions and 0 deletions

View File

@ -6,4 +6,9 @@ class HomeController < ApplicationController
@talks = Talk.ordered_by_rating
@ratings = Ratings.new
end
def export
@talks = Talk.all
@talk_preferences = TalkPreference.all
end
end

View File

@ -5,6 +5,10 @@ class TalkPreference < ActiveRecord::Base
before_create :assign_new_unique_id
def include?(id)
talks.include? id.to_s
end
private
def assign_new_unique_id

View File

@ -0,0 +1 @@
<%= CSV.generate_line([talk_preference.hashed_unique_id, talk_preference.created_at] + @talks.map(&:id).map { |talk| talk_preference.include? talk }).html_safe -%>

View File

@ -0,0 +1,3 @@
<%- headers = ['ID', 'Created at'] + @talks.map(&:id) -%>
<%= CSV.generate_line headers -%>
<%= render partial: 'talk_preference', collection: @talk_preferences %>

View File

@ -2,4 +2,5 @@ Rails.application.routes.draw do
resources :talk_preferences, only: [:index, :show, :create, :update]
root to: 'home#index'
get 'ratings' => 'home#ratings'
get 'export' => 'home#export'
end