Ruby on Rails
This article by Brad Gessler is a great cheat sheet of so many core pieces of Ruby on Rails. References to must-have gems, reference materials, video tutorials, etc.
Random notes:
attr_accessor
creates a getter and setter- When using the
mysql2
gem, for database connectivity, setting thehost
tolocalhost
inconfig/database.yml
will make Rails attempt to connect to MySQL or MariaDB over a socket rather than a TCP connection. Use a loopback IP instead.
Psych::BadAlias: Unknown alias
errorโ
Scenario: when starting a Rails application up, a
Psych::BadAlias: Unknown alias: <something>
error shows up.
This can be caused by a few things:
-
Typos in your โconfig/database.ymlโ file. Double check your aliases are specified correctly.
default: &default
adapter: mysql2
pool: 5
timeout: 5000
encoding: utf8
development: <<: *defaults # THIS IS A TYPO -
If you are running Ruby
>= 2.7.0
, Rails>= 5, < 7
, checkGemfile.lock
for thepsych
gem. Psych 4.0 introduced a breaking change for aliases. Create an entry inGemfile
to keep Psych in 3.x.gem 'psych', '< 4'
Useful Gemsโ
Searchโ
- pg_search
pg_search
andransack
can play nicely together per this GitHub comment.- See: Using custom scopes with Ransack gem in Rails
- ransack