cod*_*ain 25 ruby ruby-on-rails
我是Ruby on Rails的新手,我正在努力深入了解MVC的工作原理.
我做了以下事情:
rails new bubblesman
rails generate controller bubble
Run Code Online (Sandbox Code Playgroud)
在我的bubble控制器中,我创建了一个方法如下:
def available
puts "YEP!!!!!!"
end
Run Code Online (Sandbox Code Playgroud)
我在路线文件中添加了以下内容:
'welcome' => 'bubble#available'
Run Code Online (Sandbox Code Playgroud)
我导航到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.):
Run Code Online (Sandbox Code Playgroud)
我也不明白的是,如果我把它放在我的助手控制器而不是我的主控制器中,它一切正常.
Avi*_*r94 33
您需要available.html.erb在views/bubble/目录中创建该文件.当路线将您带到该操作时,它还会导航到该视图,因此如果您放置:
<h2>YEP!!!!</h2>
Run Code Online (Sandbox Code Playgroud)
作为该文件中的唯一一行,它应该在网页上返回给您.
在将来,您可以使用rails g scaffold bubbles,这将为您创建大部分文件(MVC)和路由.
| 归档时间: |
|
| 查看次数: |
43682 次 |
| 最近记录: |