Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying .txt file with Ruby Sinatra

Tags:

ruby

sinatra

I would simply like to display a .txt file located in my public directory onto a page. I apologise that this may seem novice but I am new to Ruby.

So far the ruby sinatra code reads:

get '/create' do
    logfile = File.open("logfile.txt")
    erb :create
end

and the erb reads:

<h2>Text file:</h2>
<%= logfile %>

Can someone tell me what I need to display this text file on my page?

like image 859
samgbelton Avatar asked Dec 03 '25 08:12

samgbelton


1 Answers

Another way to show .txt file with Sinatra(without erb).
in your script:

get '/' do
  send_file 'views/file.txt'
end

puts file.txt with content:

Heloo ! somebody here?


enter image description here

like image 85
Philidor Avatar answered Dec 05 '25 00:12

Philidor