簡體   English   中英

缺少此請求格式和變體的模板

[英]missing a template for this request format and variant

我是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文件。 當路線將您帶到該動作時,它還會將您導航到該視圖,因此,如果您放置:

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

作為該文件中的唯一一行,它應該在網頁上將其返回給您。

將來,您可以使用rails g scaffold bubbles ,它將為您創建大部分文件(MVC)和路由。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM