Lee McAlilly

Joined

2,580 Experience
24 Lessons Completed
0 Questions Solved

Activity

Ran into this as well, and Charles' solution did not work for me, but just using body.to_plain_text did. I ended up with this:

searchkick word_middle: [:body]

def search_data
{
body: body.to_plain_text
}
end

Posted in Bulk Operations in Rails Discussion

FYI, for anyone that is on the default Rails 7 / Hotwire setup and needs to tweak this, here are a few things that I needed to do to get this working:

  • Note that your data controllers, targets, and actions no longer use the . syntax that Chris used at the time of the video. That has been deprecated. You'll need to make sure they match the style as outlined here: https://www.stimulus-components.com/docs/stimulus-checkbox-select-all/. Such as data-checkbox-select-all-target="checkboxAll"

  • Make sure to use super.connect() in your stimulus controller to inherit from stimulus-select-all:
    connect() {
    super.connect()
    }

  • In order to use request.js instead of Rails.ajax, your stimulus controller should have import { destroy } from '@rails/request.js' and the request can look like something like this:
    destroy('/notifications/bulk', { body: data, responseKind: "turbo-stream" })

Note that I had to include the turbo-stream responseKind to get it to work.

  • Last, but not least, don't forget to use status: :see_other in your bulk_controller.rb redirect. Mine ended up looking like this:

def destroy
@notifications.destroy_all

respond_to do |format|
format.html { redirect_to notifications_url, status: :see_other }
end
end

My problem is that Alpine dropped support for wkhtmltopdf with version 3.14 and all of the Ruby 3+ Docker images for Alpine are 3.15+ and the wkhtmltopdf-binary gem hasn't been updated since 2016.

Surely this is a common problem: Ruby 3 on Docker Alpine and needing to use wicked_pdf but I've been doing a bunch of googling and can't figure it out.

Any ideas would be greatly appreciated. Full write-up of the issue here: https://stackoverflow.com/questions/72833181/how-to-get-wkhtmltopdf-with-a-dockerized-rails-app-with-running-ruby3-0-4-alpin

Posted in Inline Editing with Turbo Frames in Rails Discussion

How would you abstract the polymorphic path if you wanted to use the inline edit/fields partials both in forms that are namespaced like in an admin route (e.g. a form at admin/settings/show) but also a form that is not namespaced (e.g. a form at articles/show). Not sure how to abstract these polymorphic routes so that they work in both cases.

Posted in How to use Devise with Hotwire & Turbo.js Discussion

I recently ran into this as well with Rails 7. Hopefully this will be fixed in Devise soon. For the time being, I just created a new controller that I call in config/initializers/devise.rb like this config.parent_controller = 'TurboDeviseController'.

Here's full devise initializer -> https://gist.github.com/leemcalilly/9d73e1f549d9aa8f2973f5a63004ea32

And here's the new controller (app/controllers/turbo_devise_controller.rb) -> https://gist.github.com/leemcalilly/ab04e30dd8d53429939d7845b5691b83

Posted in How to use Devise with Hotwire & Turbo.js Discussion

FYI, after upgrading to Rails 7 I had to move Chris's TurboController code in this video out of initializers/devise.rb into a normal rails controller to prevent an error when starting the server. I put this code into app/controllers/turbo_devise_controller.rb and then in the devise initializer changed this line to config.parent_controller = 'TurboDeviseController' and everything worked as expected. Thanks to Nick Francisci's article on this here: https://medium.com/@nickfrancisci/devise-auth-setup-in-rails-7-44240aaed4be

Update: the consensus from GoRails Discord seems to be just create a Pundit policy for any custom action like this one.

Posted this in the GoRails discord, but thought it might be more of an evergreen question, so also sharing it here:

I'm implementing dynamic select using Hotwire just like in this episode. In Chris's example from this episode, he makes a new action named states in his AddressesController. For my similar action I had to bypass my Pundit policy to get it to work. The simplest thing was to just skip Pundit for that action like this after_action :verify_authorized, except: [:categories].

So, here's my question: Is this opening up any sort of security hole that I'm not thinking about? Is there a better way to do this? My Category model and the model for the form object where I'm using this dynamic select already have Pundit policies, so it doesn't seem like a problem, but just wanted to bounce it off someone to see if there is another way I should do this. Thanks!

How does "resizable_image: true" work? I'm assuming that because you named your validator "resizable_image_validator.rb" with a class name "ResizableImageValidator" and then calling "validates :avatar, resizable_image: true" that rails is just doing some magic here.

Is that correct? How else would your user model know where to find ResizableImageValidator ? That wasn't really clear to me in the vid.

Has anyone started getting this error recently -> "Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone."

I'm stumped on how to fix it. Added a StackOverflow question on the topic here:

https://stackoverflow.com/questions/67993633/how-to-fix-this-in-error-rails-warning-299-elasticsearch-built-in-security-fea

Posted in Custom Rails Configuration Options Discussion

This was interesting to watch you walk through the Rails source code and connect it it to something you could do. Would like to see a practical use case for this. Not really sure how I might use this.

+1 to this question!

I'm getting this same error on the login form. The registration form works correctly. I'm using "@hotwired/turbo-rails": "^7.0.0-beta.5",

From what I can tell, Chris has also updated the source code for this episode to use beta.3. Not sure what I'm doing wrong here.

Posted in docker screencast?

+1 for a Docker lesson!

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.