TIL, 2017-02-25
- Apparently,
rails-erd
bases its diagram off the models, not what a migration does, or whatdb/schema.rb
looks like. - Confusion in AR relationships: If the table you are using HAS the foreign key, use
has_one
. If the other table has the foreign key, usebelong_to
. - A
question belongs_to :correct_answer, class_name: Answer
so you can doquestion.correct_answer
(no need to add thehas_many
for the correct answer since you don’t need it yet). - Rethinking RSpec for service classes: You can use
described_class.new(params)
, then wrap it around alet
block. Example. (The Gitlab source code is very good for reviewing/”midnight reading”.) - AR relationships: Don’t forget the
validates_presence_of
forbelongs_to
associations. sed
for quotation marks ():find . -type f -exec gsed -i '' -e 's/require '"'"'rails_helper'"'"'/wutdufuk/g' {} +
- I still sort of suck in the shell. I need to be better at shell commands.
- I really want to build a Rails generator for service objects, since I’m doing it consistently anyway.
- So when you do a
validates_uniqueness_of
, you need to add an index to prevent the race condition).