I have a CSV file
Plant_ID,Short_note,Live
YCCXXX1,Description one,TRUE
YCCXXX3,Description three,FALSE
an initializer
require 'csv'
plant_table = File.read('app/assets/csv/Plant_table_(USDA_Citrus).csv')
PlantTable.destroy_all
csv = CSV.parse(plant_table, :headers => true)
csv.each do |row|
PlantTable.create!(row.to_hash)
end
which render in a view component
<% @plant_tables.each do |plant_table| %>
<tr>
<td><%= link_to plant_table.Plant_ID, plant_table %></td>
<td>PlantX, PlantY</td>
</tr>
<% end %>
but I want it to render these ONLY if the LIVE property is TRUE.
I want something like this
#plant_table_initializer.rb
require 'csv'
plant_table = File.read('app/assets/csv/Plant_table_(USDA_Citrus).csv')
PlantTable.destroy_all
csv = CSV.parse(plant_table, :headers => true)
csv.each do |row|
if csv[row][2] == "TRUE"
PlantTable.create!(row.to_hash)
end
end