当我尝试查看任何页面时,我收到上述错误。
这是我的布局/ application.html.erb代码:
<body>
<%= link_to "Store Front", root_path, id: "logo" %>
<div class="container">
<div class="row">
<aside class="span4">
</aside>
</div>
<%= yield %>
<%= render 'layouts/header' %>
<div class="container">
<div class="row">
<div class="span8">
<%= yield %>
</div>
<aside class="span4">
<%= render @cart %>
</aside>
<%= render 'layouts/footer' %>
</div>
</body>
问题是由&lt;%= render @cart%&gt;。
造成的这是我的application_controller:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include SessionsHelper
helper_method :current_order
private
def current_cart
Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
cart = Cart.create
session[:cart_id] = cart.id
cart
end
end
任何想法?
答案 0 :(得分:1)
在before_filter :current_cart
application_controller
并使用
更改current_cart
def current_cart
@cart = Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
@cart = Cart.create
session[:cart_id] = @cart.id
@cart
end
这可能会有所改变。