Mylan Connolly


1,930 Experience
11 Lessons Completed
1 Question Solved


Posted in Rails log is to big in production?

Glad to help!

For now I am simply removing the turbo_frame_tag and returning a status: :unprocessable_entity on error which causes Turbo to work in the success and error case, although it does re-render the whole page. It seems to work fine, although I am a bit curious if there's a more complete solution to this.

I seem to have an issue getting successful submissions to work in this use case.

For example, I have a form like:

<%= turbo_frame_tag record do %>
  <%= form_with model: record, local: true) do |form| %>
    <%# ... %>
  <% end %>
<% end %>

If the controller action is:

def update
  if @record.update(record_params)
    redirect_to record, notice: 'Record was successfully updated!'
    render :edit

(Note that I don't have responders in my actions because I'm creating another separate JSON API, but maybe I need to create one for turbo streams now?)

I see the error messages as expected when there is a validation error, however I do not get redirected to the :show action when the form successfully submits. From looking here it kinda seems like this isn't supported, but it seems like the idiom up until now for Rails, so I'm not sure if I'm reading this correctly. Any tips?


Posted in How do I search Action Text with Ransack?

Let's say you have an ActionText field like so:

has_rich_text :body

You can join that without defining another association like so:


One option could be to do a full text search in PostgreSQL:

joins(:rich_text_body).where("to_tsvector(action_text_rich_texts.body) @@ websearch_to_tsquery('english', ?)", phrase)

One of the reasons I went with this approach was to help make the HTML-formatted text a bit easier to search through, and give the user a bit more flexibility. For example, since I used the websearch_to_tsquery, it supports things like quoting to search for a phrase, etc.

EDIT Heh just noticed this is a rather old thread. Anyway, maybe this will help someone in the future!

Posted in New website design!

@Chris thanks for the tip on Webpacker, I'll take a look. I did notice that they had PostCSS 8 in master, but wasn't sure if it was in a usable state. I'll have to check out that advice on @apply.

Posted in New website design!

@Luke I'm using Tailwind in a few projects and I am mostly using the Tailwind helper classes and/or TailwindUI examples to mock something up quickly, and then when I'm happy with it, I'll write it in CSS. Something like:

<div class="bg-gray rounded px-3 py-2">Hello</div>

could be reimplemented as:

.gray-badge {
  @apply bg-gray rounded px-3 py-2;

At that point you can reuse that class wherever you want. I have found that the @tailwindcss/typography plugin is pretty helpful to get articles or messages formatted easily and quickly. It works pretty well with ActionText, for example.

The new version of Tailwind (2.x) is pretty exciting but I don't think it works with Webpacker until they release a new version that includes PostCSS 8.

Posted in Tracking Metrics with Ahoy and Blazer Discussion

When I installed Ahoy, I just changed the migration to have the data type be JSONB and haven't experienced any issues.

From there, you could query in Blazer using regular SQL (perhaps like):

SELECT CAST((properties->>'video_id') AS INTEGER)
  FROM ahoy_events
 WHERE = 'User Pressed Play'
   AND ahoy_events.time >= '2020-12-01 00:00:00';

This assumes that you have a field called 'video_id' in your properties hash. Basically we're fetching the string value from JSONB and then casting it to an intger. You could also join on that, potentially, like:

SELECT ahoy_events.*, videos.*
  FROM ahoy_events
  JOIN videos ON = CAST((properties->>'video_id') AS INTEGER)
 WHERE = 'User Pressed Play'
   AND ahoy_events.time >= '2020-12-01 00:00:00';

I hope this gives you some ideas. If you have something else in mind, let me know, maybe I can assist further.

Posted in A few issues with tidying up @mentions

Answering the second half of my question from a response Benjamin Hargett made in the video. Fixing the _pasteHtml method with:

this.editor.setSelectedRange([position - endPos + startPos, position + 1]);

fixes the paste issue. Still curious about the content-type though.

Posted in A few issues with tidying up @mentions

Hello, I was following along with the mentions episode here

I made a few tweaks to help suit my application a bit better, and one that I thought of was utilizing the contentType field for Trix.Attachment type in JS.

I modified the replaced method to look like this:

  replaced(e) {
    let mention = e.detail.item.original;
    let attachment = new Trix.Attachment({
      sgid: mention.sgid,
      content: mention.content,
      contentType: "x-application/user",
    this.editor.insertString(" ");

When adding new mentions, the data-trix-content-type attribute of the figure is now available, so I can style mentions specifically (nice!). However, when I go to edit a record, that content type is not persisted; instead it is replaced with application/octet-stream (not quite as nice!). First question is, is there a way to make this content type persisted somehow? If not, I'll figure out another way to style figures properly. My issue is that there's a lot of vertical margin in figures that I would probably want for an image or video, but not for mentions.

The second issue is that if I add a mention, everything is deleted from the mention to the beginning of the line in the editor. I suspect there may be a bug in the _pasteHtml method here:

  // Original version
  _pasteHtml(html, startPos, endPos) {
    let position = this.editor.getPosition();
    this.editor.setSelectedRange([position - endPos, position]);

  // Tweaked version
  _pasteHtml(html, startPos, endPos) {
    let position = this.editor.getPosition();
    this.editor.setSelectedRange([startPos, position]);

When I use the tweaked version it works fine for one mention, but when I try to mention multiple people, it starts deleting too much text again. Has anyone encountered this and/or have a solution that might work better?

Thanks a bunch, these resources have been awesome