Home>
1

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
https://gyazo.com/841c79ee5480543857955c277fb5ea72
Current state
https://gyazo.com/ffa995eee01eb19c28ae77144bfd3d0c
3 Applicable source code

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


  
    
      
      <% = "Information from # {@ user.name}"%>
      
    <table>
      <tbody>
        <tr>
          <th>name</th>
          <td><% [email protected]%></td>
        </tr>
        <tr>
          <th>Profile</th>
          <td><% = @ user.profile%></td>
        </tr>
        <tr>
          <th>Affiliation</th>
          <td><% [email protected]%></td>
        </tr>
        <tr>
          <th>Job title</th>
          <td><% [email protected]%></td>
        </tr>
      </tbody>
    </table>
      
      <% = "# {@ 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%>
  <p>
    <% = prototype.catch_copy%>
  </p>
   <% = link_to "by # {prototype.user.name}", user_path (current_user), class :: card__user%>%>

  


prototypes_controller.erb

class PrototypesController


users_controller.rb

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