Rails 3 找不到静态页面的路由
我正在通过 Ruby on Rails 教程:通过示例学习 Rails。我在标题为“主要是静态页面”的部分中。
在公共目录中创建名为 public/hello.html 的 HTML 页面后,出现错误,应如图 3.3 所示。我的问题是,当我尝试创建页面并使其显示在 localhost:3000/hello.html 时,我看不到渲染的页面。相反,我收到一个错误,显示“路由错误没有路由匹配”/ hello.html”,
我没有对路由进行任何更改;我认为 Rails 应该足够聪明,可以找到“hello.html”,因为它位于与“public/index.html”页面相同的目录,页面名称是“hello.html”,
您能解释一下吗?
Am working my way thru Ruby on Rails Tutorial: Learn Rails by Example. I'm in the section entitled Mostly Static Pages.
I get an error after I create an HTML page in the public directory which is called public/hello.html and should appear as in Figure 3.3. My problem is that when I try to create the page and make it appear at localhost:3000/hello.html I don't see the rendered page. Instead, I get an error which says "Routing error No route matches "/ hello.html"
I have not made any changes to the routing; I thought that Rails was supposed to be smart enough to find "hello.html" because it's in the same directory as the "public/index.html" page and the name of the page is "hello.html"?
Can you please explain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您像我一样正在阅读这本书,我会在前一章中让服务器保持运行状态,因此它仍在从 demo_app 目录加载index.html。
If you're like me and powering through the book, I left the server running from the prior chapter, so it was still loading index.html from the demo_app directory.
您正在遵循旧指南。较新版本
http://ruby.railstutorial.org/chapters/static-pages# sec:green
告诉你需要修改config文件夹中的routes.rb。
我为这件事哭了大约一个小时。
You're following an old guide. A newer version
http://ruby.railstutorial.org/chapters/static-pages#sec:green
tells you that you need to modify the routes.rb in the config folder.
I spent about an hour crying about this.
您确定您输入正确吗?看起来您输入的是“localhost:3000/[space]hello.html”而不是“localhost:3000/hello.html”。请仔细检查。
Are you sure you typed this correctly? It looks like you've typed "localhost:3000/[space]hello.html" rather than "localhost:3000/hello.html". Please double check.
将文件移至公共文件夹。这对我来说很有效。
我使用的提示是Rails 默认提供Public 文件夹。所以我想,如果我把它放在公共文件夹中,应该可以工作。您会看到它与索引文件一致,所以我认为这也是证据。
Move the file to the Public folder. That did the trick for me.
The hint I used is that Rails serves the Public folder by default. So I figured, if I put it in the Public folder, that ought to work. You'll see it's in line with the index file, so I think that's proof, too.
再次检查您的应用程序目录,并确保将文件保存在(我的情况):
C:\Users\Nnamdi\rails_projects\sample_app\public\hello.html
我遇到了同样的问题,但意识到我没有将其保存在正确的位置目录
..上面的解决方案应该有效..干杯
Review your app directory again and make sure you save the file in (my case) :
C:\Users\Nnamdi\rails_projects\sample_app\public\hello.html
I had the same issue but realized that I did not save it in the right directory
..The solution above should work..cheers