'零'不是与ActiveModel兼容的对象。它必须实现:to_partial_path

时间:2015-04-21 17:39:47

标签: ruby-on-rails

当我尝试查看任何页面时,我收到上述错误。

这是我的布局/ 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

任何想法?

1 个答案:

答案 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

这可能会有所改变。