[英]Ruby on Rails resources #index is missing a template for request formats: text/html
while trying to familiarize with using resources for planning routes, I encountered a weird error:在尝试熟悉使用资源来规划路线时,我遇到了一个奇怪的错误:
No template for interactive request没有交互式请求的模板
ShoppersController#index is missing a template for request formats: text/html ShoppersController#index 缺少请求格式的模板:text/html
Here are the routes mapping这是路线映射
routes.rb路线.rb
Rails.application.routes.draw do
resources :shoppers
end
shoppers_controller.rb购物者控制器.rb
class ShoppersController < ApplicationController
def index
end
def create
@shopper = Shopper.new
end
end
shoppers.html.erb购物者.html.erb
<h1>Welcome Shoppers</h1>
Does anyone know how to solve this?有谁知道如何解决这个问题?
Thanks for all the feedbacks you share.感谢您分享的所有反馈。
It's because the name of your view is wrong.这是因为您的视图名称错误。 As the error you're getting says: 'Rails expects an action to render a template with the same name contained in a folder named after its controller'
正如您收到的错误所说: 'Rails 需要一个操作来呈现一个具有相同名称的模板,该模板包含在以其控制器命名的文件夹中'
So in your case, the structure needs to be:所以在你的情况下,结构需要是:
Reference: https://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action参考: https://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action
Create a view with the name of the action in the controller!在控制器中创建一个带有动作名称的视图!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.