ファイルから文字列にコンテンツを追加しようとしています。
iso-8859-1 エンコーディングを使用してファイルを開き、文字列を同じエンコーディングに設定します。
しかし、値を連結しようとするとincompatible character encodings: UTF-8 and ISO-8859-1 (Encoding::CompatibilityError)
エラーが発生します。
両方の文字列が同じエンコーディングの場合、なぜこれが起こるのですか?
実際にはそこに UTF-8 文字列はありません。
sql = "
INSERT INTO pages
(meta_title, meta_description, meta_keywords, title, URL, content)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s');
".force_encoding('iso-8859-1') # setting string to iso-8859-1
Dir['./*'].select { |e| File.file? e }.each do |e|
f = File.open(e, "r:iso-8859-1") # opening the file using iso-8859-1
# extracting meta, title etc
puts sql % [*meta, title, url, content]
end