TIL
Sometimes we learn stuff and we share it with you fine people.
Back to all blog posts
-
· Barry Hess · TIL
TIL: Blocking Password App Autocomplete on Form Fields
I wanted to disable password managers, particularly 1Password, from interacting with a username field in Contact Me. It was pretty simple in the end:
<%= form.text_field :username, "data-lpignore": true, "data-1p-ignore": true %>
-
· James Adam · TIL
TIL: Managing Raspberry Pi software with a bit less pain
For the printer project I'm working on, most of the software behind it runs "in the cloud", but there's some software that needs to run beside each printer, to check for new things to print and manage the process of downloading and sending those things to the printer component itself.
In the current incarnation of the project, this "on the desk" software runs on a small Raspberry Pi computer, which acts as a simple bridge between your Wi-Fi and the printer, funnelling data from our servers to thing that will actually print it out.
-
· Matthew Lettini · TIL
TIL: Don’t forget your Web Manifest file
We’re primarily a web shop. We’re dipping our toes into mobile app development, but our collective expertise is in making products and services for the web. And like everyone else, our use of the web has shifted from our desktops and laptops to our phones.
As we’re creating and prototyping new ideas, we keep developing websites that we think might also be good apps. So a few of us are using “Add to Home Screen” on these products, which has mostly been great, but we ran into something annoying: we couldn’t figure out how to hide the Safari toolbars as we navigate this new website-as-app.
-
· Barry Hess · TIL
TIL: Deploying a Sinatra app to Render.com
This morning I wanted to deploy a simple Sinatra app to Render.com. It wasn’t super obvious to me, so I figured I’d write down what worked in the end.
First, a Gemfile:
# Gemfile
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'puma'* I’m pretty sure
sinatra-contrib
is not necessary.Also at this point in time you’ll need to
bundle lock --add-platform x86_64-linux
for your Render.com deployment to work.Here’s my
main.rb
"hello world" app: -
· James Adam · TIL
TIL: Turbo Stream broadcasting needs default_url_options to be set
We've been using Turbo Streams in some of our recent prototypes, which makes it really easy and fun to get responsive and fun interactions set up. However, we kept having issues with images sent in a turbo stream response.
If the response was delivered by a normal controller render, e.g.
class ThingController < ApplicationController
def update
@thing = Thing.find(params[:id])
if @thing.update(thing_params)
respond_to do |format|
format.turbo_stream # renders `update.turbo_stream.erb`
end
end
end
end... then any images included in that template would render as you'd expect.
However, any rendering that was triggered by one of the
broadcast_...
methods from turbo-rails — which is how you get content to update in "real time" across many clients — would break. So changing the controller above to something more like this: -
· Matthew Lettini · TIL
TIL: Use randomness to prevent email trimming
With conversation threading (which almost everyone has enabled), Gmail was trimming the bottom of the emails we send with our new app because they were too similar to the other emails in the conversation thread.
They’re similar because that’s just the link to get back into the app—you know, the important bit to keep our users engaged! Having that trimmed is bad.
The solution to this is silly: Gmail will not trim content if it’s always unique, so now we add a unique/random number to the bottom of every email we send. Insert eye roll.
-
· Barry Hess · TIL
TIL: Merge nested attributes in Rails permit params
I am working on a new product that's a bit more complicated than our prior releases. Getting refamiliarized with nested parameters in Rails has been interesting. In this case imagine I have a discussion that, when creating it I also want to create the first comment. The discussion information is in a form with a nested form for the comment. So at the base you have these permitted parameters:
params.require(:discussion).permit(:title, comments_attributes: [:body])
That is fine, but I wanted to assure that the discussion and comment couldn't be messed with and would always be associated with the logged in,
current_user
. Stack Overflow told me this would be pretty straightforward these days. Unfortunately that didn't work for me. Perhaps I'm doing something wrong, but I had to get a little more…into it.def discussion_params
_discussion_params = params.require(:discussion).permit(:title, comments_attributes: [:body])
_discussion_params.reverse_merge!(user_id: current_user.id)
_discussion_params[:comments_attributes].each do |key, value|
_discussion_params[:comments_attributes][key] = value.reverse_merge(user_id: current_user.id)
end
_discussion_params
endI'd be happy to hear that there's an easier way.
-
· Barry Hess · TIL
TIL: JavaScript Turbo Stream Requests
I am working on search for Album Whale and I was very confused when my JavaScript fetch requests were not resulting in turbo_stream rendering getting displayed on my page. I checked my logs to see if the render was happening. I looked for missing
<%=
tags. Debugged andlogger.info
'd all over.Then I finally noticed the following in my Rails logs:
Processing by AlbumsController#search as */*
Oh, I expected that to say something about
TURBO_STREAM
, like:Processing by AlbumsController#search as TURBO_STREAM
This sent me on a dive into headers (I didn't have an
Accept
header on myfetch
request), response handling, and the fetch API.Here's what I came up with for our first rough cut of a working, live search field (this is Stimulus code):
-
· Barry Hess · TIL
TIL: Rails Testing
I had to figure out how to run browser-based tests in Rails again. In part that meant working around my lack of Chrome. Rails System Tests with Safari.
I also had some problems with Rails Turbo Drive taking over EVERYTHING, which required me to figure out how to deal with a Rails form redirect not rendering HTML.
-
TIL: Victory Symbol
We noticed that the victory symbol at the bottom of our homepage looked different in Chrome than Safari––it was playing smart and rendered the unicode character as an emoji. Lettini found a fix though! Append this string of code to the symbol:
︎
.So
✌︎
renders to ✌︎ and not emoji. Weird.(Here’s a blogpost that explains it all.)