Rui Freitas


560 Experience
5 Lessons Completed
0 Questions Solved


I'm trying to add a toast after running a background job, i.e., the type and content of the toast depends on wether or not a certain service object called in the BG job is successful or not.

I can render the toasts correctly when I stream from a turbo_stream controller format response, but if I try to stream from the Job with Turbo::StreamsChannel.broadcast_append_to 'toasts' ... it doesn't have any error and in the logs I can see the partial was rendered but it never gets delivered to the UI.

Any ideas on how to do this?

Posted in In-App Navbar Notifications Discussion

Hey Chris, I was wondering how you would tackle the notification type in cases where the text you want to render isn't exactly the class name and there's more text that depends on the notifiable object. For example, let's say I want to have the following two notifications:

  • "John D started following you"
  • "Jane D sent you a friend request"

I did a quick test and added a `notification_to_s` method to my `Follow` and `FriendRequest` models like so:

# follow.rb
  def notification_to_s
    "following you"

# friend_request.rb
  def notification_to_s
    "you a friend request"

And then adapted the jbuilder method like this:

# index.json.jbuilder
# ...
  json.notifiable do
    json.type notification.notifiable.notification_to_s

This doesn't seem as dynamic as your example. Can you think of a better way to do this?

Posted in Direct File Uploads to S3: Part 3 Discussion

Hi Chris. I've been trying to adapt these series to implement a direct file upload with Vuejs. I'm using vue-resource as my http client and a file upload form from Element UI for Vuejs. So far I've succeeded in getting the presign json responde from the Shrine endpoint, and I sucessfully touch Amazon S3, but then get a 204 response and a strange file (XML?) gets created in my buckets instead of the file I'm trying to upload.

Any ideas on how to go about this without Jquery and/or jQuery file upload?

Posted in Rails & Vue.js Trello Clone - Part 2 Discussion

Hi Gustavo, I had the same problem... after comparing Chris' application.js file with my own, I noticed I was missing rails-ujs... This used to be a gem which has now been moved into Rails 5.1.

I was able to fixe Rails.ajax by updating my gemfile to run Rails 5.1 or above and by requiring rails-ujs in application.js

Posted in Rails & Vue.js Trello Clone - Part 2 Discussion

Hi Chris, I'm getting a "Uncaught ReferenceError: Rails is not defined" error when trying to send ajax requests with "Rails.ajax"... I've never seen this type of syntax so I'm a bit lost as to where this is coming from.

Posted in Sending Emails with SMTP and Sendgrid Discussion

Hi Chris. First of all, thanks for putting this out, GoRails has been a great resource to implement new features and learn.

I've got a file in my model that gets upload with Shrine to S3 (works perfectly) and I was wondering how can I attach that file when sending email with a Mailer?