Home>
1

If i click on the posted photo or name,
Implements the function to move to the detail page.
Among them, I want to display the name of the poster on the detail page,
I got an error code

2Error message
NameError in Prototypes # show
undefined local variable or method `prototype'for #<#<Class: 0x00007fc027ae7100>: 0x00007fc027ae5710>
Did you mean? prototype_url
3 Applicable source code

show.html.erb

<main>
  
    
    <p>
      <% = "Prototype title"%>
    </p>
    <% = link_to "by # {prototype.user.name}", ← ** Here part **
         root_path, class:: prototype__user%>
    <% # Display the following if the poster of the prototype and the logged-in user are the same%>
        
        <% = link_to "edit", root_path, class:: prototype__btn%>
        <% = link_to "Delete", root_path, class:: prototype__btn%>
        
    <% # // Show the above if the prototype poster and the logged-in user are the same%>
      
      <% #<% = image_tag "prototype image"%>%>
      
      
        
        <p>Catch copy</p>
        <p>
          <% = "Catch copy of prototype"%>
        </p>
        
        
        <p>Concept</p>
        <p>
          <% = "Prototype concept"%>
        </p>
        
      
      
      <% # Display the following comment posting form for logged-in users%>
        <% #<% = form_with local: true do | f |%>
            
            <% #<% = f.label: hoge, "comment"%><br />
            <% #<% = f.text_field: hoge%>
            
            
            <% #<% = f.submit "submit", class:: form__btn%>
            
        <% #<% end%>
      <% # // Display the above for logged-in users%>
      <ul>
        <% # Describe the process of listing the comments associated with the post%>
          <li>
            <% #<% = "Comment text"%>
            <% #<% = link_to "(username)", root_path, class:: comment_user%>
          </li>
        <% # // Describe the process to list the comments associated with the post%>
      </ul>
      
    
  
</main>


prototypes_controller.rb

class PrototypesController</pre>
<p><br />
_prototype.html.erb</p>
<pre><code>
<% = 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}", prototype_path (prototype.id), method:: get, class:: card__user%>

  


4 What I researched and tried
I thought I couldn't associate with user,
Check the association
user model
has_many: prototypes

prototype model
belongs_to: user
I was able to confirm the description of
5 Supplementary information such as the version of the tool i am using

  • Answer # 1

    This is in the Private method (under = private), so I think it should be under def index ~ end

    def show
        @prototype = Prototype.find (params [: id])
      end

    Also, the corresponding error part,prototype.user.nameHowever, as shown above, @proptype is defined, soprototype.user.nameI feel like I need to

Related articles