Skip to content

Commit 1a163cc

Browse files
committed
fix bug when data directory is not available
1 parent 956bc15 commit 1a163cc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/models/quote.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ def body
88
end
99

1010
def save
11-
quotes_file = File.open("./data/quotes.txt", "a")
11+
quotes_file = File.open(quotes_file_path, "a")
1212
quotes_file.puts(@body)
1313
quotes_file.close
1414
end
1515

1616
def self.all
17-
File.read("./data/quotes.txt").each_line
17+
File.read(quotes_file_path).each_line
1818
.map{|x| Quote.new(x.strip) }
1919
end
20+
21+
DATA_DIR = Rails.root.join("data")
22+
FileUtils.mkdir_p(DATA_DIR)
23+
def quotes_file_path
24+
DATA_DIR.join("quotes.txt").to_s
25+
end
2026
end

0 commit comments

Comments
 (0)