私はRubyとRubyonRailsを初めて使用し、Max OSXLionでRuby1.9.2とRails3.2.5を使用しており、「Railsを使用したアジャイルWeb開発(第4版)」という本を読んでいます。
第6章で概説した次のコマンドを使用して、サンプルデポアプリを作成しました。
- Railsの新しいデポ
- Railsは足場を生成します製品タイトル:文字列の説明:テキストimage_url:文字列価格:10進数
- rake db:migrate
- Railsサーバー
Safariで「http:// localhost:3000 / products」を指定すると、次のアクションコントローラーが表示されます。製品リストページが表示される代わりに、例外が発生しました。エラーメッセージが表示されます。
Routing Error
No route matches [GET] "/products"
Try running rake routes for more information on available 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
この本の正誤表とフォーラムを検索しても、考えられる解決策は見つかりませんでした。
前もって感謝します。