Ruby on rails RoR-第一个应用程序项目,路由到主视图而不是/blog\u条目
在命令行中创建并迁移数据库后,我无法让rails正确路由到“http://localhost:3000/blog_entries--它只显示默认视图,与http://localhost:3000". 如果我将blog_entries index.html.erb中生成的代码轨添加到application.html.erb视图中,它将显示预期的结果 rake routes为我提供了以下信息:Ruby on rails RoR-第一个应用程序项目,路由到主视图而不是/blog\u条目,ruby-on-rails,ruby,routing,routes,Ruby On Rails,Ruby,Routing,Routes,在命令行中创建并迁移数据库后,我无法让rails正确路由到“http://localhost:3000/blog_entries--它只显示默认视图,与http://localhost:3000". 如果我将blog_entries index.html.erb中生成的代码轨添加到application.html.erb视图中,它将显示预期的结果 rake routes为我提供了以下信息: blog_entries GET /blog_entries(.:format)
blog_entries GET /blog_entries(.:format) blog_entries#index
POST /blog_entries(.:format) blog_entries#create
new_blog_entry GET /blog_entries/new(.:format) blog_entries#new
edit_blog_entry GET /blog_entries/:id/edit(.:format) blog_entries#edit
blog_entry GET /blog_entries/:id(.:format) blog_entries#show
PUT /blog_entries/:id(.:format) blog_entries#update
DELETE /blog_entries/:id(.:format) blog_entries#destroy
root / home#index
My routes.rb包含以下内容(atm…已在数小时内搜索解决方案,我尝试的所有操作均失败):
结束
我对rails非常陌生,并且很难理解为什么rails会将URL路由到application.html.erb”http://localhost:3000/blog_entries". 我已经查阅了文档,搜索了谷歌和stakoverflow几个小时了,但我自己却找不出答案。非常感谢您的帮助--我相信答案很简单,但我就是不明白。
应用程序是您的布局。其中有
,该产量
呈现当前控制器/动作的视图。换句话说,您的布局(application.html.erb
)呈现每个请求,并在其中呈现请求的特定视图。%溴
同时从public/
目录中删除index.html
。删除get“blog\u entries”
,这是错误的,只需使用资源:blog\u entries
应用程序不包含
,即使删除了所有ERB,问题仍然存在。此外,我在公共目录中没有看到index.html。将
添加到应用程序.html.erb
中,您还可以在执行请求后检查日志以查看呈现了哪些视图。
RubydRailed::Application.routes.draw do
resources :blog_entries do
get "blog_entries"
end