【发布时间】:2012-05-07 07:49:07
【问题描述】:
我创建了一个没有问题的脚手架
$ rails 生成脚手架新名称:字符串标题:字符串内容:文本
运行迁移的 Rake 命令(没有问题,表正确创建)
$ rake db:迁移
编辑 app/views/home/index.html.erb
'新闻' %>
我在“http://localhost:3000”中正确看到了主页和链接;点击链接“我的新闻”页面“http://localhost:3000/news”加载没有错误。
现在,点击 Rails 生成的链接“New New”,链接的目标 localhost:3000/news/new (source "New New"),我阅读此错误:
路由错误
没有路由匹配 {:action=>"show", :controller=>"news", :format=>nil}
尝试运行 rake 路线以获取有关可用路线的更多信息。
在“app/views/news/index.html.erb”中的链接源是
在 routes.rb 我读过
MyApp::Application.routes.draw 做
资源:新闻
获取“主页/索引”
- Rails 3.2.3
- Ruby 1.9.3p125
- MySQL 5.5
- Windows 7 64 位
耙路线:
news_index GET /news(.:format) news#index
POST /news(.:format) news#create
new_news GET /news/new(.:format) news#new
edit_news GET /news/:id/edit(.:format) news#edit
新闻 GET /news/:id(.:format) news#show
PUT /news/:id(.:format) news#update
删除 /news/:id(.:format) news#destroy
home_index GET /home/index(.:format) home#index
根目录/home#index
提前谢谢我的英语对不起
【问题讨论】:
-
生成的链接的目标是什么?你能从生成的源中复制那行吗?
-
是的,链接的目标是localhost:3000/news/new
标签: ruby-on-rails-3 routing scaffolding