缺少此请求格式和变体的模板 [英] missing a template for this request format and variant

查看:40
本文介绍了缺少此请求格式和变体的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Ruby on Rails 的新手,正在努力深入了解 MVC 的工作原理.

I am new to Ruby on Rails and am trying to gain a strong understanding of how MVC works.

我做了以下事情:

rails new bubblesman 
rails generate controller bubble

在我的气泡控制器中,我创建了一个方法,如下所示:

in my bubble controller I created a method as follows:

def available
  puts "YEP!!!!!!"
end

我将以下内容放在我的路由文件中:

I put the following in my routes file:

'welcome' => 'bubble#available'

我导航到 http://localhost:3000/welcome我收到以下错误:

I navigate to http://localhost:3000/welcome I get the below error:

ActionController::UnknownFormat (BubbleController#available is missing a template for this request format and variant.

request.formats: ["text/html"]
request.variant: []

NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not… nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.):

我也不明白的是,如果我把它放在我的辅助控制器而不是我的主控制器中,它一切正常.

what I also don't understand is if I put this in my helper controller instead of my main controller it all works fine.

推荐答案

您需要在 views/bubble/ 目录中创建 available.html.erb 文件.当路线将您带到该操作时,它也会将您导航到该视图,因此如果您输入:

you need to create the available.html.erb file within the views/bubble/ directory. When the route takes you to that action, it also navigates you to that view, so if you put:

<h2>YEP!!!!</h2>

作为该文件中的唯一一行,它应该在网页上返回给您.

as the only line in that file, it should return that to you on the webpage.

将来,您可以使用 rails g scaffold bubbles,这将为您创建大部分文件 (MVC) 和路由.

In the future, you could use rails g scaffold bubbles and that will create a majority of the files (MVC) and routes for you.

这篇关于缺少此请求格式和变体的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆