I have successfully deployed my first Rails app on production mode to a Digital Ocean Droplet. I have developed the app in my local computer with some Turbo Frames working correctly, but in production environment, the Turbo Rails is not working at all.
I have read this thread Turbo-rails not functioning in production but this is not my case, as I don't see errors in my browser console.
I am using ruby 3.1.3, rails 7.0.6. Links work as HTML regular links.
I have tried doing:
RAILS_ENV=production rails turbo:install
I have also tried doing:
RAILS_ENV=production rails turbo:install:redis
And reload nginx server but it is not working.
In the production.log file there are no errors, just shows that when I click a link that should work as a turbo frame, it behaves as a HTML regular link.
This is the first time I ask a question here, so forgive me if there is lack of details.
EDIT
By not working I mean that links that I have inside turbo_frame_tags does not lead to only updating the content inside the turbo frame but instead refreshes the whole page. I am absolutely not sure that all my javascript components are initializing properly. As I am new to the language I have verified everything I could, running assets:precompile does not throw an error if it helps
These are the portions of the code that are not working:
edit.html.erb:
<div class="top-padding">
<%= turbo_frame_tag "new_item" %>
<%= link_to "Agregar ítem", new_invoice_invoice_item_path(@invoice), data: { turbo_frame: "new_item" }, class: "btn btn-info" %>
</div>
new.html.erb:
<%= turbo_frame_tag "new_item" do %>
<%= render 'form' %>
<% end %>
When I click on the link_to showed in the edit.html.erb file in development, it renders the code in the new.html.erb file inside the "new_item" turbo_frame_tag on the edit.html.erb page.
In development environment, the console log shows this:
Started GET "/invoices/249/invoice_items/new" for ::1 at 2023-09-20 08:30:12 -0300
Processing by InvoiceItemsController#new as HTML
Parameters: {"invoice_id"=>"249"}
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:7:in `set_current_user'
Invoice Load (1.0ms) SELECT "invoices".* FROM "invoices" WHERE "invoices"."id" = $1 LIMIT $2 [["id", 249], ["LIMIT", 1]]
↳ app/controllers/invoice_items_controller.rb:4:in `new'
**Rendering layout C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/turbo-rails-1.4.0/app/views/layouts/turbo_rails/frame.html.erb
Rendering invoice_items/new.html.erb within layouts/turbo_rails/frame**
ProductCategory Load (0.9ms) SELECT "product_categories".* FROM "product_categories" ORDER BY nombre ASC
↳ app/views/invoice_items/_form.html.erb:5
Rendered invoice_items/_form.html.erb (Duration: 292.5ms | Allocations: 4561)
Rendered invoice_items/new.html.erb within layouts/turbo_rails/frame (Duration: 297.3ms | Allocations: 4954)
Rendered layout C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/turbo-rails-1.4.0/app/views/layouts/turbo_rails/frame.html.erb (Duration: 317.0ms | Allocations: 5249)
Completed 200 OK in 351ms (Views: 328.0ms | ActiveRecord: 3.0ms | Allocations: 7711)
In production environment, the console log shows this:
I, [2023-09-20T11:32:48.395055 #301414] INFO -- : [e395a581-dda5-4c86-81f5-d45192437773] Started GET "/invoices/58/invoice_items/new" for 190.97.11.201 at 2023-09-20 11:32:48 +0000
I, [2023-09-20T11:32:48.398207 #301414] INFO -- : [e395a581-dda5-4c86-81f5-d45192437773] Processing by InvoiceItemsController#new as HTML
I, [2023-09-20T11:32:48.398298 #301414] INFO -- : [e395a581-dda5-4c86-81f5-d45192437773] Parameters: {"invoice_id"=>"58"}
I, [2023-09-20T11:32:48.465989 #301414] INFO -- : [e395a581-dda5-4c86-81f5-d45192437773] Rendered invoice_items/new.html.erb within layouts/application (Duration: 61.6ms | Allocations: 116>
I, [2023-09-20T11:32:48.468273 #301414] INFO -- : [e395a581-dda5-4c86-81f5-d45192437773] Rendered layout layouts/application.html.erb (Duration: 64.0ms | Allocations: 12766)
I, [2023-09-20T11:32:48.468709 #301414] INFO -- : [e395a581-dda5-4c86-81f5-d45192437773] Completed 200 OK in 70ms (Views: 59.2ms | ActiveRecord: 7.7ms | Allocations: 13874)
UPDATE: Following Axel recommendations:
- I ran
RAILS_ENV=production rails turbo:install - I do have
import "@hotwired/turbo-rails"in app/javascript/applications.js - I do have
<%= javascript_importmap_tags %>in my layouts/application.html.erb file - I have the line
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: truein my config/importmap.rb file - I don't have a app/assets/javascripts folder. Maybe there is some issue?
- I opened the Netowrk tab and I do have a turbo.min-something.js file that it being loaded
- I tried to check if my local code is the same as my production server code and I haven't found any differences