Ask coding questions

← Back to all posts
How to access backend vars on the frontend in Ruby
JacobMcPherson1 (239)

How would I access the visitor's var in my index.html file?

Answered by CodingCactus (4326) [earned 5 cycles]
View Answer
CodingCactus (4326)

you should use erb files, not html ones

A little example:


get "/" do
    @randnum = rand(1..10)
    erb :index


<p><%= @randnum %></p>

If you need some explanation, let me know!

JacobMcPherson1 (239)

@CodingCactus It works fine, but can you explain what an erb file is? Thank you!

CodingCactus (4326)

@JacobMcPherson1 you may want to google it as I'm not very good at explaining it, but basically it's like ejs but ruby