Posted almost 7 years ago. Visible to the public. Repeats.

Always, always declare your associations with symbols

Never ever declare your associations with a string, especially when doing metaprogramming. A common mistake is something like

# WRONG class Page < ActiveRecord::Base %w[main sub].each do |type| belongs_to "#{type}_title" end end # RIGHT class Page < ActiveRecord::Base %w[main sub].each do |type| belongs_to "#{type}_title".to_sym end end

Always append a to_sym, otherwise you'll have all kinds of fun.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Tobias Kraze
Last edit:
12 months ago
by Besprechungs-PC
belongs_to, has_one, has_many
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Tobias Kraze to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more