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 on rails - "undefined method` id 'for nil: nilclass "error occurs when users/show action (view my page) is execut
- ruby on rails - nomethoderror: undefined method `each' for 5:integer
- ruby on rails - undefined method `content' error cannot be resolved
- ruby on rails - i want to solve the error of undefined method `total_pages' that occurred while using gem: kaminari
- ruby on rails - undefined method `id 'appears and i am stuck without knowing the cause
- ruby on rails undefined method `password_digest='
- ruby on rails 5 - undefined method `each 'for error in each of view
- ruby on rails - actionview::template::error (undefined method ~
- ruby on rails - in rails command, undefined method `application' for rails:module (nomethoderror) comes out
- ruby on rails - undefined method `' for nil:nilclass in rake assets:precompile after deploy is executed
- ruby - undefined method `map' for nil: nilclass cannot be resolved
- ruby - error resolution for undefined method `coments' for nil:nilclass
- ruby on rails - is this ok for the procedure to add a new rails update method?
- [ruby on rails] when using the save method, a validation error occurs without setting any validation
- windows - [rails] undefined method `authenticate! 'for nil: nilclass
- ruby - please tell me how to resolve the undefined method `id' for nil:nilclass error in rails
- ruby on rails - i get no method error in rspec
- ruby - undefined method `event_url 'for error cannot be resolved
- ruby - rails variable, method error
- [ruby on rails] i want to use pluck method to display the values separated by "," in the form field
- 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
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- python 3x - import error "cannot import name '_imaging'"