'Why can't I display my ruby on rails app on localhost?
I'm trying to display a very simple app from codecademy and this is the error I'm getting in my browser:
PagesController#welcome is missing a template for request formats: text/html
NOTE! Unless told otherwise, Rails expects an action to render a template with the same name, contained in a folder named after its controller. If this controller is an API responding with 204 (No Content), which does not require a template, then this error will occur when trying to access it via browser, since we expect an HTML template to be rendered for such requests. If that’s the case, carry on.
pages_controller.rb
class PagesController < ApplicationController
def welcome
end
end
routes.rb
Rails.application.routes.draw do
root ‘pages#welcome’
end
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Portfolio</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,500,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
welcome.html.erb
<h1>Hello</h1>
Running 'rails server' and getting the above error in my browser. As far as I can tell the files are in the right place and of the right type ... Rails v 6.0.1
Solution 1:[1]
Apparently the issue was that my project was in a folder the title of which had a space in it.
After moving the project to a different folder it now works.
This is on rails 6.0.1
Solution 2:[2]
I deleted my controller and view that had the issue and the auto-generated the controller and view with
rails g controller controllername new create
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vkuz91 |
Solution 2 | Lucas Masaba |