Added the ability to comment on articles in Ruby on Rails5.
Checking the show page with no comment data, @ entry.comments.size is
It is set to 1 in the initial state, and an error occurs in the comment.user.name part of partial.
I also checked the rails console, but the number of comments was 0.
Thanks for your professor.
<% = @ entry.comments.size%>#Displays 1 here. <% = render: partial =>"comments/comment",: collection =>@ entry.comments%>
2.3.0: 006>Comment.all Comment Load (0.2ms) SELECT "comments". * FROM "comments" LIMIT? [["LIMIT", 11]] =>#<ActiveRecord :: Relation > 2.3.0: 010>comments.size (0.3ms) SELECT COUNT (*) FROM "comments" WHERE "comments". "Entry_id" =? [["Entry_id", 1]] =>0
<% = comment.user.name%> <% = comment.body%>
class Comment<ApplicationRecord belongs_to: user belongs_to: entry validates: body, presence: true end class Entry<ApplicationRecord belongs_to: podcasts has_many: comments end
Answer # 1
size includes unsaved records.
Is the process like
@ enty.comments.buildconfused by the controller?
I think that it is an error because user is empty in the comment before saving after building.
- ruby - undefined method `map' for nil: nilclass cannot be resolved
- ruby on rails - actionview::template::error (undefined method ~
- ruby on rails 6 - i want to resolve undefined method `' for nil:nilclass
- ruby on rails - undefined method `' for nil:nilclass in rake assets:precompile after deploy is executed
- ruby on rails - in rails command, undefined method `application' for rails:module (nomethoderror) comes out
- ruby on rails - undefined method `name' for nil:nilclass
- ruby on rails - how to resolve undefined method `errors' for nil:nilclass
- ruby on rails - undefined method `content' error cannot be resolved
- ruby on rails - nomethoderror: undefined method `each' for 5:integer
- ruby - nomethoderror in posts#edit undefined method `content' for nil:nilclass in rails
- the ruby on rails each method does not repeat well
- ruby on rails ruby calculation method description method
- ruby - nomethoderror: undefined method `method name' for nil: please tell me how to deal with nilclass
- [ruby on rails] i want to use pluck method to display the values separated by "," in the form field
- ruby on rails - about the judgment method of whether or not you like rails
- ruby - error resolution for undefined method `coments' for nil:nilclass
- ruby - undefined method `build_address' for order (table doesn't exist): class send data to db
- ruby on rails - i want to use yield in a method chain
- 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 on rails 5 - nomethoderror in text_field method
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- python - importerror: cannot import name md5 error cannot be resolved