I am currently creating a posting app.
I would like to introduce active storage and carrierwave to enable posting of images and videos, but I am currently stuck with an error.
As for what I went to
・ Introduction of active storage
・ Description of has_one_attached
-Definition of information received by the controller
-Description to be displayed in the view (see error statement)
I'm new to rails. Thanks for your support.
NoMethodError in Comments # index Showing /Users/Desktop/debate-app/debate-app/app/views/comments/index.html.erb where line # 37 raised: undefined method `image'for #<Comment :: ActiveRecord_AssociationRelation: 0x00007f8ce24cec00>
Corresponding source code
<% end%> <% end%> <% if @ comments.image.attached?%><-This is the image here <% = image_tag @ commented.image%> <% end%> <% if @ comments.image.attached?%>
--comment model-- class Comment
Supplementary information (FW/tool version, etc.)
--comments controller-- class CommentsController
I'm sorry that the text is poor.
If i have any missing or interesting code, please leave a comment.
Answer # 1
@comments = @ debate.comments.includes (: coach)
Put binding.pry above here, @comments = @ debate.comments.includes (: coach)
How about seeing if you can get the value with and if you can get the value with @ comments.image?
Since the image is linked to one comment, I feel that this method at present will not work.
If you do it with @comments
@ comments.each do | comment | if comment.image.attached?
I think that it will not work unless you put out one by one with each do etc. like this.
- ruby - an error occurs when building a rails 6 environment with docker
- ruby - [rails] about the error that occurs when deleting likes (routing error)
- ruby on rails - about image posting page argumenterror
- ruby on rails - creating an image posting application where the data entered in the form is not saved
- an error occurs when migrating the django app on heroku
- ruby on rails - i cannot save a comment on the comment posting page
- ruby on rails - i want to display the posted image in the background using image_tag or url_for
- same source error occurs when hitting twitter api from client side with fetch
- ruby on rails - error with automatic deployment by capistrano
- ruby on rails 5 - about lint/syntax error of rubocop
- ruby - [rspec] error in "dependent: destoy" test: how to resolve "validation failed"
- ruby - i want to avoid the mysql2 :: error: unknown table'likes' error that appears when deploying to heroku
- ruby on rails - the image cannot be saved in s3 and cannot be displayed in the view aws :: sigv4 :: errors :: missingcredentials
- i want to eliminate the error that occurs when starting the springboot application
- dart: about the error that occurs when declaring a list with const
- ruby - i want to delete the registered contents, but i get an error saying nomethoderror in posts # index
- ruby - i get a validation error when using factorybot with rspec
- ruby on rails - i want to resolve rails name error
- ruby on rails - unknown action error when trying to post a comment