Dino Maric

January 4, 2023

Rails engine bugs and a small contribution

Since I've done a lot of work on tailwind-css rails engine, I've noticed that there is one issue.
Integrating this engine inside rails engine is problematic as reported here and here.

My first idea is to generate a new rails engine, try to make this work and see what steps are required.

I will generate new `--mountable` engine just so I get all the engine bells and whistles
rails plugin new tw_test --mountable
cd tw_test

After navigating inside newly created engine and opening gemspec file, I can see that file is not properly aligned.

Screenshot 2023-01-04 at 12.28.52.png


It is a small issue with how erb handles whitespaces and new line so I've fixed this in Rails.
https://github.com/rails/rails/pull/46640

------------------------

Alright, back to my main goal 😀

I'll go ahead and generate scaffold just so I've something to work with
bin/rails g scaffold User name email
bin/rails db:migrate

After creating the scaffold and navigating inside `test/dummy` to boot the application and see if everything works, I'm getting a strange error:

Screenshot 2023-01-04 at 11.40.43.png


What the heck is happening here, this should work!
After double checking with the Rails guides, yep this should work, looks like another bug 😅

Judging by the error message my dummy app can't be booted, there is no puma? Lets see...


Both boot.rb and puma.rb are properly generated, but as you can see dummy app uses Gemfile from the root engine, which makes sense since this dummy app is just for the testing purposes.

Lets see how my engine Gemfile looks like


Screenshot 2023-01-04 at 12.04.43.png


Hmm, I wounder if puma is missing here, lets try adding puma and booting dummy app again.

Screenshot 2023-01-04 at 12.07.17.png


Cool, cool! I can boot my dummy app now.

This means I should submit another Rails PR to add puma gem when generating new engine.

---------------------------

Rails generators are inside railties, specific method that dumps entries inside the engine gemfile is here.
So I just need to add puma in the gemfile_entries array.

But, before I submit new PR I'll check on the rails master if someone already fixed this issue.
Oh nice, looks like this issue is already fixed.

Judging by the comment form Rafael, looks like this was not working for a long time :)
We should just add puma to the engine's gemfile. This stoped work after webrick was removed from Ruby core, but people should not have to configure anything else. Things should just work.


--------------------------


I've spent a lot of time on this and I feel a bit exhausted, I will continue working on my initial goal, later :)

✌️ 

















About Dino Maric

Hey! I'm Dino, programmer and CTO of WizardHealth.
Subscribe bellow to follow my ramblings about programming for the web.