Agile Web Development with Rails 7: page 113 - Seeing the list of products [solved]

I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113.

Iteration A1 - Seeing the list of products

I am using windows 10 but when I attempt to run the ruby bin/dev command described for windows users,I see the error:
Traceback (Most recent call last)
ruby: no Ruby script found in input

Has anyone else seen this?
Any suggestions on how I can move forward.

I am able to start the server on its own, but for some reason can’t get that bin/dev script to run.

Thanks

Is there a bin/dev file on your system? What does it contain?

That does seem to be my problem.
No bin/dev file is created when I create the application.

Is that something that should be created by rails automatically?

If you specify --css tailwind a bin/dev file is created. If you don’t specify a --css or --js option, no bin/dev file will be created.

Thanks for coming back to me @rubys . I did use the --css tailwind command, but hit another issue which might be related when I ran [rails new depot2 --css tailwind]:

rails aborted!
TZInfo::DataSourceNotFound: tzinfo-data is not present. Please add gem ‘tzinfo-data’ to your Gemfile and run bundle install

When I check my Gemfile, there is already a record as follows;

Windows does not include zoneinfo files, so bundle the tzinfo-data gem

gem “tzinfo-data”, platforms: %i[ mingw mswin x64_mingw jruby ]

I found some guidance on stack overflow as follows:

ruby - TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows - Stack Overflow

But the gemfile does already have that x64_mingw attribute.

I tried removing platforms and running bundle update, which seems to run successfully, including a line: Using tzinfo-data 1.2021.5

I wonder if maybe the tzinfo-data issue is causing the issue with bin/dev not being created?

Ran an additional test without the --css tailwind command extension and still get:

rails aborted!
TZInfo::DataSourceNotFound: tzinfo-data is not present. Please add gem ‘tzinfo-data’ to your Gemfile and run bundle install

Looks like that was reported on Rails 4. I see another report from two years ago: tzinfo-data issue when starting new rails project - Stack Overflow with Rails 5. Now you are seeing it with Rails 7.

So it is not just you, but clearly is is not affecting every Windows user. Debugging this remotely is not going to be easy. And there always is the concern that once you solve this problem that will only prepare you to get to the point where you encounter the next problem.

I’m going to describe two options, and I’m going to encourage the first option, as that is what I use myself and am very happy with it.

First option

Most Rails developers use MacOS machines. Most Rails apps are deployed on Linux. This makes these two the preferred environments for Rails.

Windows 10 and above can run something called WSL2, which gives you a pristine Linux install. If you are running Windows 11, you can install WSL2 from the App Store. Otherwise, open a command prompt as administrator and run wsl --install. Go with the default Linux distribution (currently Ubuntu 20.04).

I highly recommend both Windows Terminal (also from the App Store) and Visual Studio Code (from the App Store for Windows 11 users, installable from the web site for everybody else).

The end result is literally seamless - you can edit your files using VS Code, run commands via Windows Terminal, and access your server via Microsoft Edge browser as localhost.

And because it is a separate environment, it is not affected by things you may have installed in the past, and won’t affect things you may install in the future. And you are not installing things from a third party - everything I listed above is from Microsoft.

And if you have questions, I am here to help as I have this installed myself (as well as “native” windows and Mac OS/X).

Option 2

For reasons I don’t yet understand, Rails is producing a Gemfile that doesn’t work for you. So what we need to do is to stop the installation process in the middle, correct the Gemfile, and then complete the installation. And Rails provides an option to do exactly that:

rails new depot --skip-bundle

Correct the Gemfile per instructions you can find on Stack Overflow and other places. And then proceed with the rest of the installation:

bundle install
bundle add tailwindcss-rails
bundle binstubs bundler
ruby bin/rails importmap:install
ruby bin/rails turbo:install stimulus:install
ruby bin/rails tailwindcss:install

This should get you to the exact place you would be if Rails had generated a Gemfile that worked for you. If you get this to work, I would suggest opening an issue with Rails so that they can fix it for others, and I would appreciate it if you shared that information with me, here, so that I can update the book in a way that may benefit others.

Hi @rubys - Thank you very much for the suggestions.

Have been working through Option 1 and have successfully installed WSL2 (with Ubuntu), Terminal and VS Code. When I attempt to run rails new depot --css tailwind in the Ubuntu home, I get the following response:
-bash: /mnt/c/Ruby31-x64/bin/rails: ruby: bad interpreter: No such file or directory

Does this mean it has found my windows Ruby installation via a mounted drive?
Or is it expecting a local Ruby install on Ubuntu?
My question at this point is:
Should I install Ruby and Rails on the Ubuntu distro?
Or is there some sort of mapping I need to resolve between WSL2 and my Windows Ruby / Rails version?

Re: Option 2
I followed your suggested steps and found that I did get a bin/dev file this time around.
All worked as expected, but when I try to run ruby bin/dev, I get the following error:
C:\Ruby31-x64\bin\ruby.exe: no Ruby script found in input (LoadError)

This is the content of that bin/dev file:
if ! command -v foreman &> /dev/null
then
echo “Installing foreman…”
gem install foreman
fi

foreman start -f Procfile.dev

Happy to help test anything else and share it here.
Let me know your thoughts.
Regards, Heinz

Regarding option 1: Yes, Yes, Yes, and No.

In other words, do proceed with the Ubuntu installation instructions from the book. Once that is done, it will find the Linux version of Ruby. Until you install Ruby on Ubuntu, it will find the Windows version and try to use that. With option 1, you don’t want to be using your Windows Ruby or Rails executables.

Regarding option 2: Sorry about that, That’s not a Ruby script but actually a bash script. So the way to run that would be “bash bin/dev”. Alternately, bin/dev is merely a convenience - it allows you to run multiple things in one window. If you look at Procfile.dev you will see two commands in it. You can run each in a separate terminal window.

I very much appreciate you working through this. I’ll update the book with lessons learned and recommendations that will help future readers. Meanwhile, I’ll be here to help you get up and running.

Ran into the same issue following the examples for depot with tailwind not working in Windows initially. I was able to get tailwind to work after running this command: rake tailwindcss:build and then re-running the webserver.