ruby-for-beginners | learning Ruby for our beginners groups
kandi X-RAY | ruby-for-beginners Summary
kandi X-RAY | ruby-for-beginners Summary
You can read it online here. This book is built using middleman. The source code is kept on the main branch. The build directory is .gitignored and should be initialized with another git repository so it can be pushed to the gh-pages branch in order to deploy changes to the site.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ruby-for-beginners
ruby-for-beginners Key Features
ruby-for-beginners Examples and Code Snippets
Community Discussions
Trending Discussions on ruby-for-beginners
QUESTION
I am following this post and trying to add a validate method before object creation. I keep getting undefined method 'video' for #
I am reading this article here http://ruby-for-beginners.rubymonstas.org/ getting to know how ruby works but cannot figure out why I get this error.
http://api.rubyonrails.org/v5.1/classes/ActiveModel/Validations/ClassMethods.html#method-i-validate
If I call new on a ruby object and save it with a validation what do I need to do to the video variable to not get undefined method
?
ANSWER
Answered 2017-Jul-19 at 09:04as video
method actually doesn't exists on your model, and based on post you're following it's actually a reference you should just simple replace video
with self
. Something like this: if self.reload.count >= 9 errors.add(:base, "Exceeded video limit of 9 videos") end Let me know if this works for you ! Regards
New Answer :
On post you're following, they are checking videos
as association and then checking if its count bigger then 9.
How it works is actually is that the main object which is referenced to the videos
is not stored to DB but it has videos
association so you can check length/count of that.
In your case, if you're trying to do that on your main object ( Video
) you will get an error that it couldn't be find as it's not persisted but just instantiated as well as your validation method is called before create
.
This way you're trying to achieve, it's logical only for validating creating some referenced model, which can't be stored has more then 9 videos.
Hope it's clear enough ?
Regards
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ruby-for-beginners
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page