I have an old Ruby on Rails project from 6 years ago that was deployed on Heroku. I haven’t touched it in so long that Heroku deleted my account and now I’m looking to deploy it again on Render. I had to update to Ruby 3.2.2, Rails 7 and React 18. I deployed my app to Render and it successfully builds and deploys but when I go to the webpage I don’t see any errors in the console. I just see text “React is not working” which comes from my views/static_pages/root.html.erb
file:
<script type="text/javascript">
window.currentUser = <%= render(
partial: "api/users/user",
locals: { user: current_user },
formats: [:json],
handlers: [:jbuilder]
).html_safe %></script>
<% end %>
<div id="root">React is not working</div>
I open the sources tab in chrome devtools and see this layout:
.
|-index.js
|-assets
|-application.js
|-application.css
|-page_icon.png
I open the application.css
and all of my css is there. and it gets the page_icon.png
perfectly fine. But when I open the application.js
I don’t see any of the code from the bundle.js
file in there. All I see is actioncable code from a cable.js
from what I’m assuming is coming from app/assets/javascripts/cable.js
, I’m assuming it’s this because I see this in the file:
console.log("DEPRECATION: action_cable.js has been renamed to actioncable.js u2013 please update your reference before Rails 8"),
in my app when i run npm install
it installs the packages and puts the bundle.js in the app/assets/javascripts/
directory and in my app/assets/javascripts/application.js
I have this:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require activestorage
//= require jquery
//= require jquery_ujs
//= require_tree .
and in views/layouts/application.html.erb
file I have this:
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
I read somewhere that Rails 7 is moved away from sprockets so I tried installing this gem:
gem 'sprockets-rails'
but this didn’t seem to do anything.
This webapp works fine locally but for some reason it just doesn’t work when I deploy it on Render. I can share other code snippets or the Github repo if it helps. Any inputs would be greatly appreciated.