【发布时间】:2016-09-09 10:56:38
【问题描述】:
我是 ROR 的新手,我正在阅读 Ruby on Rails 官方指南 (4.2.6),但是当我想添加 Article 模型时遇到了一个问题。
当我尝试保存文章时出现错误,
undefined method `article_url' for # 你的意思是?文章网址
我发现路由中没有“article”前缀:
majiandeMacBook-Pro:blog majian$ bin/rake routes 在进程 26766 中通过 Spring 预加载器运行 前缀动词 URI 模式控制器#Action welcome_index GET /welcome/index(.:format) 欢迎#index 根 GET / 欢迎#index 文章 POST /articles(.:format) 文章#create new_articles GET /articles/new(.:format) 文章#new edit_articles GET /articles/edit(.:format) 文章#edit 获取 /articles(.:format) 文章#show PATCH /articles(.:format) 文章#update PUT /articles(.:format) 文章#update 删除 /articles(.:format) 文章#destroy但是在文档中,我发现应该是这样的:
文章 GET /articles/:id(.:format) 文章#show有人知道为什么路线不同吗?任何帮助将不胜感激。
【问题讨论】:
-
向我们展示您的
routes.rb -
请提供routes.rb的代码
标签: ruby-on-rails