2 posts about #programming

StimulusReflex + ActiveStorage + Localhost

As it turns out, when you're working with StimulusReflex and ActiveStorage to store Images for a given model, you need to setup default_url_options in development.rb to

 config.action_controller.default_url_options ={ host: 'localhost', port: 3000 }

otherwise, they will be rendered with www.example.org/ host and won't show properly

Learned by carlos-muniz on Mar 8, 2021

973983 adforcodereview v3 0211021 c02 021121

Strip and downcase email addresses if you're using them as lookup keys for anything

Seems like something I need to learn every few years, and recently popped up on one of my side projects. If you're relying on email addresses as lookup keys, for instance in authentication/login scenarios, then standardize on lowercase and strip whitespace for good measure.

This came up when a customer was not able to get inbound email processing to work for his account. Turns out that his user record had a properly downcased email, but his SMTP server was sending his email address with capitalization. Some string massaging fixed the immediate issue.

User.find_by(email: reply_params["sender"].to_s.downcase)

After putting this fix in, I found everywhere else in the system that email addresses come in as input and gave them the same treatment.

Learned by obie-fernandez on Feb 17, 2021

973983 adforcodereview v3 0211021 c02 021121