I recently downloaded and installed the latest versions of Ruby (3.4.1) and Rails (8.0.1). I created a Rails project and generated a controller with
bin/rails generate controller Say hello goodbye
Then I started the server and entered "localhost:3000/say/hello" in my browser. The web page displays without errors. Next, I replace the code in hello.html.erb with:
<p>
It is now <%= Time.now %>
</p>
I got the following error when I refreshed my browser:
FYI, I've installed Ruby and Rails in Ubuntu 24.04, Windows 11 WSL, and Mac OSX Sequoia using:
Windows - https://rubyinstaller.org/downloads/ (Ruby+Devkit 3.3.7-1 (x64))
Ubuntu (vm running on Mac Parallels) - https://gorails.com/setup/ubuntu/24.04
Mac OSX - https://gorails.com/setup/macos/15-sequoia'
Each time I get the same result. How do I fix this?
You are getting this error because the code you copied includes not only normal whitespace but other invisible characters too. This is what a normal white space looks like and behaves:
whitespace = " "
whitespace.bytes
#=> [32]
But yours are different. This one is copied from between the =
and the Time.now
:
your_space = " "
your_space.bytes
#=> [226, 128, 139, 32]
This is a version with normal whitespace:
<p>
It is now <%= Time.now %>
</p>