Hi everyone. I’m new to Rails so trying to read all the documentation.
While reading through the Getting Started with Rails I’ve noticed that there is no section about article Comments validation, but I think it would be great to have such chapter. It is hard for me to make it up for now, so I would appreciate any guidance on how to create Comment validation(mandatory author and body) and show errors of invalid submission to the user.
I’m looking for a way to do something like you suggest in Article validation, I’ve tried to modify it in some ways, but it didn’t work.
Thank you for any help.
We use @comment = Comment.new(article: @article) instead of @comment = Comment.new in articles_controller.rb because we are going to add comment that associate to an article. I hope it helps anyone who try Ruby on Rails in Ruby on Rails guides.
PS: I just try Ruby and Ruby on Rails around two weeks and I’m still not fluently to use these tools. I’m using GitHub Copilot to assist me to solve this problem.