4

enter image description here

I previously run the

rails generate controller Welcome index

command on terminal and just directly run the server, but this error message keep occuring:

No template for interactive request
WelcomeController#index is missing a template for request formats: text/html

I have tried looking for solutions but none can resolve the issue.

These are the file path enter image description here

and inside it only contains:

Hello,Rails!

Heinrich
  • 73
  • 1
  • 8
  • Are there any codes? – Udo E. Dec 21 '19 at 12:44
  • You have to add a view file at app/views/welcome/index.html.erb https://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action – arieljuod Dec 21 '19 at 14:33
  • @arieljuod The file was generated automatically by the rails when i generate the controller so I don't need to add a new file on my own right? – Heinrich Dec 22 '19 at 08:11
  • @UdoE. The codes were the default code generated when creating the controller. I have not modified anything yet.. and just wanna straightly running the server. – Heinrich Dec 22 '19 at 08:18

9 Answers9

5

I was getting this error as well. Turns out I accidentally had the folder that had my html.erb files inside of my layouts.

views/layouts/welcome/index.html <- wrong

views/welcome/index.html <- correct

user2031423
  • 347
  • 4
  • 7
3

I have found the solution to my problem. But I was confused why. Previously, I run the rails server on a git bash command line and it keeps spitting out the error message I show above. But then, I try to make a new app using Windows command line and repeat the same steps and run the server and it works! I was wondering what happen with my git bash command line. Does it have to do with PATH? or maybe I was missing something when I installed git bash?

The reason i said that is because when I run the rails server on my Windows command line, I saw that there is a [compiling...] step before finally running my server, but this steps does not occur when I run rails server on git bash. Can anybody provide an explanation about this?

Sorry, for the long-winded message. I am truly new to rails-react!! Thanks..

Heinrich
  • 73
  • 1
  • 8
2

I had this issue and I managed to resolve it by ensuring the file paths were free of spaces. In my case my mounted drive was called "HDD (Mint)" changing it to "HDD-Mint" resolved this.

Zhorian
  • 802
  • 1
  • 9
  • 15
  • I dont get which drive you meant previously – Heinrich Dec 22 '19 at 10:53
  • I am sorry I am not very clear about the drive rename action.. Is it the name of the project(app) that we rename? – Heinrich Dec 22 '19 at 10:55
  • if my ruby files is in the C: drive, should I make the project in C drive as well? It does not matter anyway right?? @Zhorian – Heinrich Dec 22 '19 at 11:17
  • Changed my drive name to no spaces, but still does not resolve the issue – Heinrich Dec 22 '19 at 11:27
  • I'm using linux not windows so the root to my project is /mnt/HDD-Mint/Repo/udemy-ror/projects/intro if think the whole path needs to be devoid of spaces but I could be wrong. I just know this sorted my problem out. – Zhorian Dec 22 '19 at 15:54
2

just to add to @Zhorian's answer...

I resolved my error by removing special characters from the folders in the filepath as well (parentheses, in my case).

2

Make sure you don't use spaces and/or parenthesis in your Rails pathname, for example:

\Users\username\Dropbox (company)\my_rails_app

So this problem currently occurs when working with Dropbox Business.

It's considered as a bug in Rails, a fix has already been made, but not yet available in the Rails version 6.0.2.1

https://github.com/rails/rails/pull/37119 https://github.com/rails/rails/issues/37719 https://github.com/rails/rails/issues/37641

P.S. I think the 'space' problem was fixed already before, but the 'parenthesis' problem still remained in Rails 6.0.2.1

Paul Verschoor
  • 1,479
  • 1
  • 14
  • 27
  • Thanks for this, been driving me mad for hours trying to work out what I was doing wrong. :-/ – Paul Danelli Feb 22 '20 at 13:02
  • Unfortunately, I get this error on a Linux Centos 7, no special charachters nor whitespaces in the path. Also my templates are in place, I see in the log that they are being rendered. – Phipsen Mar 04 '20 at 19:03
  • @Phipsen Out of curiousity, what is the absolute path you use? – Paul Verschoor Mar 05 '20 at 18:16
  • @PaulVerschoor: I needed to add a subdir for the template. Was posting a separate question and did get an answer: [link](https://stackoverflow.com/questions/60540462/rails-6-0-2-actionmailer-issue-template-not-found) – Phipsen Mar 13 '20 at 07:48
1

Do not run $rails s on the terminal of vs code or other IDEs. This will output this error dues to wrong directory pointer. Use the default system Command Prompt. This helped to correct the error.

Chrisphine
  • 164
  • 6
1

I was running into this same issue and what resolved it for me was being sure that the capitalization of the directories for the file path in my terminal, which was running the server matched exactly (i.e. OneDrive/Documents/GitHub/blog, not onedrive/documents/github/blog).

WesG303
  • 11
  • 1
0

It's a very strange one. I had the same but instead make my controller name plural:

rails generate controller Welcomes index

And your routes.rb

# If this page will be your homepage ie /
root to: 'welcomes#index'

You'll notice your views becomes plural: views/welcomes/index.html.erb

Sylar
  • 11,422
  • 25
  • 93
  • 166
0

In the VSCode the "views/layout" folder stands for views->layout subfolder. If you place your html file there, the controller will not find it. It is expected to be under "views"