缺少此请求格式和变体的模板

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

我做了以下事情:

rails new bubblesman rails generate controller bubble 

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

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

我在路线文件中添加了以下内容:

 'welcome' => 'bubble#available' 

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

 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.): 

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

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

 

YEP!!!!

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

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