require 'csv'

class CardsController < ApplicationController
  def index
   @cards = read_cards_from_csv
   render json: @cards
  end

  private

  def read_cards_from_csv
   csv_file_path = Rails.root.join('public','cards.csv')
   cards = []
   CSV.foreach(csv_file_path, headers: true) do |row|
    cards << { name: row['name'],type: row['type'],photo_url: row['photo_url'],description: row['description'] }
   end
   cards
  end
end
