RoR:'nil'不是与ActiveModel兼容的对象,它返回有效的部分路径

时间:2012-09-18 02:51:27

标签: ruby-on-rails-3

好的,所以我试图根据hidden_​​tag_field显示两个不同位置的用户微博,hidden_​​tag_field是数据库中名为kind的列。这种是“购买”或“微博”。

app / views / users / show.html.erb(我想要显示两个列表)

<section>
        <div id= "purchases">
          <%= render 'shared/micropost_form_purchase' %>
          <div class="row">

          <div class="span8">

            <% if @user.microposts.any? %>

              <ol class="microposts">
                <%= render @purchases %>
              </ol>

            <% end %>
          </div>
          </div>

        </div>
        <div id="sales">
          <% if @user.microposts.any? %>
            <ol class="microposts">
              <%= render @sales %>
            </ol>
          <% end %>
        </div>
          </section>

然后在app / controllers / microposts.rb

def show

    @microposts= Micropost.all
    @purchases = @microposts.where(:kind => "purchase")
    @sales = @microposts.where(:kind => "sale")


  end

@purchases和@sales出现错误。最后这里是app / views / microposts / _micropost.html.erb

<li>
  <span class="content"><%= micropost.content %></span>
  <span class="timestamp">
    Posted <%= time_ago_in_words(micropost.created_at) %> ago.
  </span>
  <% if current_user?(micropost.user) %>
    <%= link_to "delete", micropost, method:  :delete,
                                     confirm: "You sure?",
                                     title:   micropost.content %>
  <% end %>
</li>

这是错误:

Completed 500 Internal Server Error in 11ms

ActionView::Template::Error ('nil' is not an ActiveModel-compatible object that returns a valid partial path.):
    12:             <% if @user.microposts.any? %>
    13:             <h3>Purchases I am interested in (<%= @user.microposts.count %>)</h3>
    14:               <ol class="microposts">
    15:                 <%= render @purchases %>
    16:               </ol>
    17:               
    18:             <% end %>
  app/views/users/show.html.erb:15:in `_app_views_users_show_html_erb__315023603463182203_22059740'

0 个答案:

没有答案