Polymorphism in 6 steps

A slightly advanced association in ActiveRecord is called polymorphic association. This usually happens when a model can belong to more than one model, even if it behaves the same way, but it’s easier to understand with an example. Suppose you have a blog that has articles, photos, and events. You want to add comments on...
Read More

Model validations in Rails

Validations are pretty much a “check” that records won’t be saved unless certain attributes/params meet a specified criteria. They can all done in the models and they can be done in a single line per attribute. For example, if we have a Painting model, inside the class(model) we have: validates :name, presence: true, uniqueness: true...
Read More

CRUD with Active Record

Say you’re creating a blog. A blog has many posts, and a post belongs to a blog. I’ll use the “Post” class for these examples, however these can be substituted with any class name (capital and singular!). Create There’s essentially a couple of ways to create a new record. One way of doing it: p...
Read More