I have a question about a rails 7 project I’m starting. I have a controller HomeController
with one action home
.
class HomeController < ApplicationController
def home
render
end
end
I have a root route
root to: "home#home"
And a view file app/views/home/home.html.erb
<% debugger %>
hello this is here
My app/views/layouts/application.html.erb
is pretty standard:
<% debugger %>
<!DOCTYPE html>
<html>
<head>
<title>Chargemaster</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>
<body>
hello
<%= yield %>
</body>
</html>
When I run rails s
and try to hit the home route, I get an empty page. The output tells me it was processed as HTML and completed ok:
Started GET "/" for ::1 at 2024-06-13 16:29:12 -0700
Processing by HomeController#home as HTML
Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms | Allocations: 134)
But it doesn’t halt at any of the breakpoints and doesn’t display any text - neither the “hello” in application.html.erb
or the “hello this is here” in home.html.erb
.
The rendered output looks like this:
<html>
<head>
<meta name="color-scheme" content="light dark"></head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;"> </pre>
</body>
</html>
Why is this action not rendering the templates as I expect?
If it helps feel free to look at the codebase at https://github.com/fredwillmore/climate-control.
This is because your ApplicationController
extends ActionController::API
(i.e. light version for API controllers) instead of ActionController::Base
.
In your app/controllers/application_controller.rb
file you should change:
class ApplicationController < ActionController::API
...
end
To:
class ApplicationController < ActionController::Base
...
end