0

わかりました。データベースのkindという列であるhidden_​​tag_fieldに基づいて、2つの異なる場所にユーザーのマイクロポストを表示しようとしています。この種類は「購入」または「マイクロポスト」のいずれかです。

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'
4

0 に答える 0