Add export functionality
This commit is contained in:
parent
e997f1d042
commit
db36fa09c6
@ -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
|
||||
|
@ -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
|
||||
|
1
app/views/home/_talk_preference.csv.erb
Normal file
1
app/views/home/_talk_preference.csv.erb
Normal 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 -%>
|
3
app/views/home/export.csv.erb
Normal file
3
app/views/home/export.csv.erb
Normal file
@ -0,0 +1,3 @@
|
||||
<%- headers = ['ID', 'Created at'] + @talks.map(&:id) -%>
|
||||
<%= CSV.generate_line headers -%>
|
||||
<%= render partial: 'talk_preference', collection: @talk_preferences %>
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user