shridhar
shridhar

Reputation: 35

Failure/Error: get :show, :id => @user

I'm going through a Rails tutorial. In the chapter 11th when I add this code

<% if @user.microposts.any? %>
        <table class="microposts" summary= "User microposts">
        <%= render @microposts %>
        </table>
        <%= will_paginate @microposts %>
        <% end %>

I get two errors as followed

1) UsersController GET 'show' should show the user's microposts
   Failure/Error: get :show, :id => @user
   ActionView::Template::Error:
     Missing partial microposts/micropost with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/home/ruby/new_rails/rail_new_app/app/views"
   # ./app/views/users/show.html.erb:10:in `_app_views_users_show_html_erb___4312949856623214655_35714500__2182421899600364460'
   # ./spec/controllers/users_controller_spec.rb:100:in `block (3 levels) in <top (required)>'

 2) UsersController GET 'show' should paginate microposts
   Failure/Error: get :show, :id => @user
   ActionView::Template::Error:
     Missing partial microposts/micropost with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/home/ruby/new_rails/rail_new_app/app/views"

Please let me know where I'm wrong.

Upvotes: 0

Views: 848

Answers (2)

Kalisa Falzone
Kalisa Falzone

Reputation: 1

Sounds like you solved this but just in case others are going through the Hartl tutorial and get this error see:

Listing 11.21: A partial for showing a single micro post.

This is where the file is created in the tutorial.

Make sure the file you created has this name:

app/views/microposts/_micropost.html.erb

Also make sure the file has the appropriate content.

Upvotes: -1

pdu
pdu

Reputation: 10423

Error: Missing partial microposts/micropost

Which is because of <%= render @microposts %> needing a partial to render the collection of microposts, like the error says.

Caveat: If you just provide an object and let rails determine the partial by itself, it will default to :pluralized_model_name/_:singular_model_name, which is microposts/_micropost in your case. If you want rails to render another partial for your collection, you need to explicitly specify it; render partial: 'user/microposts', collection: @microposts.

You just need to create the partial. And read the error messages, they're helpful.

Upvotes: 2

Related Questions