Ruby on Rails2.0 チュートリアル 「Webアプリケーション開発方法」その2。
続きです。というか、途中経過です。
セッションカートの作成というところまでは来たんですが、ここで問題が。
カートに追加しようとすると、
Unknown action
No action responded to show
これが出ちゃいます。
showアクションは確かにないんですが、それに代わるdisplay_cartアクションなるものを作っているはずなんです。
app/controller/ordering_controller.rbは以下の通り。
class OrderingController < ApplicationController def index @articles = Article.items respond_to do |format| format.html # index.html.erb format.xml { render :xml => @articles } end end def add_to_cart article = Article.find(params[:id]) @cart = find_cart # add_article()メソッドはapp/models/cart.rb内に記述 @cart.add_article(article) redirect_to(:action => 'display_cart') end def display_cart @cart = find_cart @items = @cart.items end private def find_cart session[:cart] ||= Cart.new end end
「カートに追加する」というリンクはadd_to_cartアクションになっているのですが、メソッド内でdisplay_cartにリダイレクトしているのでそっちに行く…
app/view/ordering/display_cart.htmlは以下の通り。
<% @page_title = "現在のカート内容" -%> <table> <!--ここで使用されている@itemsは、orderingコントローラーの ! display_cart()メソッドに記述されています。 ! item.articleでarticleモデルのオブジェクトを取得 --> <% for item in @items article = item.article -%> <tr> <td><%= item.quantity %></td> <td><%= article.title %></td> <td align="right"><%= item.unit_price %></td> <td align="right"><%= item.unit_price * item.quantity %></td> </tr> <% end -%> </table>
表示して欲しいんですけど…してくれない…
えー。そんなとこで詰まるとか意味不明です。
アクションの流れが何処かで壊れているのだろうか…