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
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
Related articles
- ruby - rails even if i create a new model (user), it is not displayed
- ruby - the view of the search screen is not displayed
- ruby on rails - when i make a message, i want the date to be displayed, but i get "undefined method` strftime' for nil: nil
- ruby - [rails] actioncontroller :: parametermissing is displayed when using fields_for and data is not saved
- ruby on rails 5 form_for not displayed
- ruby - images in assets files are not displayed correctly in the rails app
- ruby - nothing is displayed even if docker attaches and i cannot debug [rails 6]
- ruby - [rails] actioncontroller::parametermissing is displayed and data is not saved
- ruby - ambiguous column name error is displayed
- ruby - when the search result of the model is displayed by the function to see more in kaminari, the whole is displayed instead
- ruby on rails - unnecessary things are displayed in the data display of cms comfortable mexican sofa of rails
- ruby on rails post content is not displayed
- ruby - no route matches [patch] is displayed and comments cannot be saved in db
- ruby - "no such file or directory" is displayed even though the file exists
- ruby - when deploying heroku, heroku | welcome to your new app! is displayed and you cannot deploy
- ruby on rails - i want the link destination to be displayed normally
- "ruby on rails" how can i move to the user details page displayed in the user search?
- ruby - [vs code] the terminal cannot be displayed normally
- ruby on rails 6 - a migration file is generated, but it is not displayed in the file list next to vscode also, the contents desc
Related questions
- ruby - passing variables using render partial
- ruby - deployment error on heroku
- ruby - output the total integer value held by each user
- ruby - i want to use the search method for active hash data
- ruby - destroy action does not respond
- ruby - how do you see the rails controller relative path? (carrierwave directory deleted)
- ruby - when deploying on capistrano, i get the error "access denied for user'ec2-user' @'localhost' (using password: no)&qu
- javascript - run multiple times with js + each do
- how to reflect the layout downloaded from the external site in ruby on rails?
- ruby - how nice! function routes do not pass well (relation) [rails]
This is in the Private method (under = private), so I think it should be under def index ~ end
Also, the corresponding error part,
prototype.user.name
However, as shown above, @proptype is defined, soprototype.user.name
I feel like I need to