【发布时间】:2012-06-10 00:38:31
【问题描述】:
我是 Ruby 和 Ruby on Rails 的新手,正在 Max OSX Lion 上使用 Ruby 1.9.2 和 Rails 3.2.5,并且正在阅读“Agile Web Development with Rails (4th Edition)”一书。
我已经使用第 6 章中概述的以下命令创建了他们的示例 depot 应用程序:
- rails 新仓库
- rails 生成脚手架 Product title:string description:text image_url:string price:decimal
- rake db:迁移
- Rails 服务器
当我将 Safari 指向“http://localhost:3000/products”时,我收到以下操作控制器:异常捕获错误消息,而不是看到产品列表页面:
Routing Error
No route matches [GET] "/products"
Try running rake routes for more information on available routes.
在终端中运行“rake routes”给了我:
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
以下行已自动添加到 routes.rb。
resources: product
products_controller.rb 中还有一个索引方法。
class ProductsController < ApplicationController
# GET /products
# GET /products.json
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @products }
end
end
搜索本书的errata 和forums 没有找到任何可能的解决方案。
提前致谢。
【问题讨论】:
标签: ruby-on-rails-3 rails-routing