On the user's My Page (app/views/users/show.html.erb)
Using a partial template (app/views/prototypes/_prototype.html.erb)
I want to display a list of photos posted by users
Do not show.

2Error message
<% = Render partial:'prototypes/prototype', collection: @prototypes%>
I use a partial template with, but it doesn't show up
 No error code is displayed
Ideal state
Current state
3 Applicable source code

User's My Page (app/views/users/show.html.erb)

      <% = "Information from # {@ user.name}"%>
          <td><% [email protected]%></td>
          <td><% = @ user.profile%></td>
          <td><% [email protected]%></td>
          <th>Job title</th>
          <td><% [email protected]%></td>
      <% = "# {@ user.name}'s prototype"%>
    <% = render partial:'prototypes/prototype',
Collection: @prototypes%>← ** Here part **

Partial template (app/views/prototypes/_prototype.html.erb)

<% = link_to prototype_path (prototype.id), method:: get do%>
<% = image_tag prototype.image.variant (resize: '300x300'), class :: card__img if prototype.image.attached?%>
<% end%>
  <% = link_to prototype.title, prototype_path (prototype.id), method:: get, class:: card__title%>
    <% = prototype.catch_copy%>
   <% = link_to "by # {prototype.user.name}", user_path (current_user), class :: card__user%>%>



class PrototypesController


class UsersController

4 What I researched and tried
Check the association
user model
has_many: prototypes
has_many: comments

prototype model
belongs_to: user
has_many: comments, dependent:: destroy

comment model
belongs_to: prototype
belongs_to: user
I was able to confirm the description of

Also in the app/views/users/directory
I copied _prototype.html.erb and put it in
Was not displayed

5 Supplementary information such as the version of the tool i am using

  • Answer # 1

    collectionThe space in front of is not full-width.

    class UsersController

  • Answer # 2

    I don't understand that it doesn't cause an error, but ...
    Forget @ prototypes.each | prototype | in partial

  • Answer # 3

    Variable name to pass to the partial template@prototypesWhen
    Variable name described in the partial templateprototypeI think you should match .id and so on.

    Change the variable names ofand@prototypeChange to
    In@prototypeI think that it will be solved by adding the description to generate.

Related articles