mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
Add Paper model, Paper.import_from_csv
This commit is contained in:
parent
f661631dd9
commit
d39f00165e
4 changed files with 56 additions and 1 deletions
19
app/models/paper.rb
Normal file
19
app/models/paper.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'csv'
|
||||
|
||||
class Paper < ActiveRecord::Base
|
||||
class << self
|
||||
def import_from_csv(csv_string)
|
||||
CSV.parse(csv_string, headers: true) do |row|
|
||||
attributes = {
|
||||
name: row['name'],
|
||||
url: row['url'],
|
||||
reference: row['reference'],
|
||||
paper_type: row['paper_type'],
|
||||
originator: row['originator'],
|
||||
published_at: row['published_at'],
|
||||
}
|
||||
create!(attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue