So I been developing my app in dev environment and finally finished it and said to myself hey lets start deploying this to and oh boy I'm stressed and tired troubleshooting this and now im troubleshooting locally first then once its good locally ill try it again.
I was troubleshooting some nonsense for 2 hours then you can actually use this code to run your server RAILS_ENV=production RAILS_LOG_TO_STDOUT=true bin/rails s to get some logs and got this
Use Ctrl-C to stop
I, [2024-09-12T15:21:22.272468 #341] INFO -- : [ff2ff043-058a-481e-84eb-7eb515ee311e] Started GET "/" for at 2024-09-12 15:21:22 +0800
I, [2024-09-12T15:21:22.274372 #341] INFO -- : [ff2ff043-058a-481e-84eb-7eb515ee311e] Processing by QuestsController#index as HTML
I, [2024-09-12T15:21:22.284516 #341] INFO -- : [ff2ff043-058a-481e-84eb-7eb515ee311e] Rendered quests/index.html.erb within layouts/application (Duration: 3.2ms | Allocations: 2020)
I, [2024-09-12T15:21:22.294080 #341] INFO -- : [ff2ff043-058a-481e-84eb-7eb515ee311e] Rendered layout layouts/application.html.erb (Duration: 12.8ms | Allocations: 10616)
I, [2024-09-12T15:21:22.294488 #341] INFO -- : [ff2ff043-058a-481e-84eb-7eb515ee311e] Completed 200 OK in 20ms (Views: 15.2ms | ActiveRecord: 0.0ms | Allocations: 13357)
I, [2024-09-12T15:21:22.373347 #341] INFO -- : [97fead6c-b159-4231-8ac8-13d4c01dbc35] Started GET "/assets/controllers/modal_controller" for at 2024-09-12 15:21:22 +0800
F, [2024-09-12T15:21:22.373926 #341] FATAL -- : [97fead6c-b159-4231-8ac8-13d4c01dbc35]
[97fead6c-b159-4231-8ac8-13d4c01dbc35] ActionController::RoutingError (No route matches [GET] "/assets/controllers/modal_controller"):
[97fead6c-b159-4231-8ac8-13d4c01dbc35]
I, [2024-09-12T15:21:22.376465 #341] INFO -- : [ffab0339-9946-4ef9-82ec-a8c727bc61ab] Started GET "/assets/controllers/sidebar_controller" for at 2024-09-12 15:21:22 +0800
F, [2024-09-12T15:21:22.376991 #341] FATAL -- : [ffab0339-9946-4ef9-82ec-a8c727bc61ab]
[ffab0339-9946-4ef9-82ec-a8c727bc61ab] ActionController::RoutingError (No route matches [GET] "/assets/controllers/sidebar_controller"):
[ffab0339-9946-4ef9-82ec-a8c727bc61ab]
I, [2024-09-12T15:21:22.379721 #341] INFO -- : [671b9bf1-dc2d-4d08-9210-aa1ad92ca307] Started GET "/assets/controllers/dropdown_controller" for at 2024-09-12 15:21:22 +0800
F, [2024-09-12T15:21:22.380544 #341] FATAL -- : [671b9bf1-dc2d-4d08-9210-aa1ad92ca307]
[671b9bf1-dc2d-4d08-9210-aa1ad92ca307] ActionController::RoutingError (No route matches [GET] "/assets/controllers/dropdown_controller"):
[671b9bf1-dc2d-4d08-9210-aa1ad92ca307]
When I saw that I did my best to figure out as of why in prod env the stimulus controller is trying to do a GET route. I doubled check the controllers listed here and while they do have async/fetch it shouldn't be called in the first place because I haven't clicked any button yet.
Like modal_controller for example
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static targets = ["modalTitle", "modalBody"];
showLoginForm() {
this.modalTitleTarget.innerText = "Log In";
fetch("/quests/render_login_form")
.then(response => response.text())
.then(html => {
this.modalBodyTarget.innerHTML = html;
})
.catch(error => console.error('Error:', error));
}
showRegistrationForm() {
this.modalTitleTarget.innerText = "Sign Up";
fetch("/quests/render_registration_form")
.then(response => response.text())
.then(html => {
this.modalBodyTarget.innerHTML = html;
})
.catch(error => console.error('Error:', error));
}
}
What it only does is go to render_registration_form method in quest controller.
Now after I decided that there is no issue about it being a routing issues I move on and thought it might be missing when even though I always precompile my assets
Nope its here:
ls public/assets/controllers
alert_controller-8fcc2f524e9683ca6dec0c03f40affbc76fb27ae1250895f1f6de41b8ae4b197.js
alert_controller-8fcc2f524e9683ca6dec0c03f40affbc76fb27ae1250895f1f6de41b8ae4b197.js.gz
application-daa9025259f63a3d42a78c64248d40b3692a110c02034170bb9eddd118fe02f1.js
application-daa9025259f63a3d42a78c64248d40b3692a110c02034170bb9eddd118fe02f1.js.gz
delete_controller-d3f8d75e1df10113e91febc80cf167a0ca866e5f2eb7609ae4ed8ea1ab7af0a8.js
delete_controller-d3f8d75e1df10113e91febc80cf167a0ca866e5f2eb7609ae4ed8ea1ab7af0a8.js.gz
dropdown_controller-2a3e853c6f22b32fd60ffa202576520ca4225bcdd2ac63c6654ee8867ca55ed6.js
dropdown_controller-2a3e853c6f22b32fd60ffa202576520ca4225bcdd2ac63c6654ee8867ca55ed6.js.gz
editable_controller-4f595a3d9252502cdb9af5a235e58b9eb3457d5c0aafb192a21ab2bfffab9e5a.js
editable_controller-4f595a3d9252502cdb9af5a235e58b9eb3457d5c0aafb192a21ab2bfffab9e5a.js.gz
form_controller-2b68559aebe0d4a012794752cb37f31fd237381f072b0a4ac8d3c16568727a05.js
form_controller-2b68559aebe0d4a012794752cb37f31fd237381f072b0a4ac8d3c16568727a05.js.gz
hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js
hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js.gz
index-31a9bee606cbc5cdb1593881f388bbf4c345bf693ea24e124f84b6d5c98ab648.js
index-31a9bee606cbc5cdb1593881f388bbf4c345bf693ea24e124f84b6d5c98ab648.js.gz
indexdb_controller-3da24e3af1aeea3e59990afbdf0567c48144ee8d08d646d8807800457d48e105.js
indexdb_controller-3da24e3af1aeea3e59990afbdf0567c48144ee8d08d646d8807800457d48e105.js.gz
modal_controller-7aca490e5766b11b0f16013a88a4184a4703fe6b26d95c4c79fb375c8c109625.js
modal_controller-7aca490e5766b11b0f16013a88a4184a4703fe6b26d95c4c79fb375c8c109625.js.gz
quest_controller-c77dfba92de404a19837dc56ded2c5ff97f455275de9a328f12f18cdcf98c658.js
quest_controller-c77dfba92de404a19837dc56ded2c5ff97f455275de9a328f12f18cdcf98c658.js.gz
sidebar_controller-19fa4568277298cbea4f82fbb7f3069c2b38acf34358f75d7de17ad73bdd19f7.js
sidebar_controller-19fa4568277298cbea4f82fbb7f3069c2b38acf34358f75d7de17ad73bdd19f7.js.gz
task_controller-1255db7eef191b3b980897fff03850649d9e764711f1a98c42370940fa5d2ec5.js
task_controller-1255db7eef191b3b980897fff03850649d9e764711f1a98c42370940fa5d2ec5.js.gz
theme_toggle_controller-04aca0d091ad85b08336bab8c6bfdf68f9b45813ab5a8f9675f2305c7a2ea330.js
theme_toggle_controller-04aca0d091ad85b08336bab8c6bfdf68f9b45813ab5a8f9675f2305c7a2ea330.js.gz
trunc_controller-b3deb0dd6edadebf2ac5ed03f085cea3c4a408d7fdf1dc6b8d4994c6a48a0c4a.js
trunc_controller-b3deb0dd6edadebf2ac5ed03f085cea3c4a408d7fdf1dc6b8d4994c6a48a0c4a.js.gz
Then It might be not being called properly? And at this point I do not know what is happening so I asked chatgpt and claude and been circling in these 7 files adding and removing same lines again and again.
application.html.erb (here i am attaching the importmap)
<head>
<title>YourApp</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' %>
<%= javascript_importmap_tags %>
</head>
importmap.rb
pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin "flowbite", to: "https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.0/flowbite.turbo.min.js"
app/javascript/controllers/application.js
import { Application } from "@hotwired/stimulus"
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading";
import ModalController from "./modal_controller";
import SidebarController from "./sidebar_controller";
import DropdownController from "./dropdown_controller";
const application = Application.start()
eagerLoadControllersFrom("controllers", application);
application.register("modal", ModalController);
application.register("sidebar", SidebarController);
application.register("dropdown", DropdownController);
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }
app/javascript/application.js
import "@hotwired/turbo-rails";
import "controllers";
import "flowbite"
production.rb
require "active_support/core_ext/integer/time"
Rails.application.configure do
# FOR DEPLOYMENT POSSIBLE FIXES
config.public_file_server.enabled = true
config.assets.compile = false
config.assets.digest = true
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = true
config.active_storage.service = :local
config.log_level = :info
config.log_tags = [ :request_id ]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
config.active_support.report_deprecations = false
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
end
assets.rb
Rails.application.config.assets.version = "1.0"
Rails.application.config.assets.preload_links_header = false
Rails.application.config.assets.precompile += %w( controllers )
manifest.js
//= link_tree ../images
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link_tree ../builds
//= link_directory ../stylesheets .css
Can anyone help a brother out. It's my first app which a simple To-do app and I've spent 4 grueling weeks to finish it.