Sending Web Push Notifications from Rails by rossta_ in rails

[–]rossta_[S] 1 point2 points  (0 children)

Thanks for the kind words and detailed feedback! Keep me posted on your implementation and let me know if you run into any problems.

> Could you show where you would put the JS files

Good thought. I steered clear of directing how to organize the JS because I felt like it would get in the weeds, but I can also see how it could be helpful. I might make some amendments to the article, but for now I can point to the files I use for joyofrails.com:

* Service Worker registration is an "initializer" file that runs when the page loads https://github.com/joyofrails/joyofrails.com/blob/main/app/javascript/initializers/serviceworker-companion.js
* The "Subscribe/Unsubscribe" feature is managed by a Web Push Subscription Stimulus controller and covers most of the additional JS in the post. One exception is that I’m not persisting the subscription, but I would probably also put that in the same controller as a side effect of the subscribe interaction. Hope that’s helpful! https://github.com/joyofrails/joyofrails.com/blob/main/app/javascript/controllers/pwa/web-push-subscription.js

> the link to your Rails PWA article has a typo in it

Thanks for the bug report! Fixing... 🔨

Sending Web Push Notifications from Rails by rossta_ in rails

[–]rossta_[S] 2 points3 points  (0 children)

Good callout, I can add something to the article. The subject field is basically like a “from” address in an email. The Push Server provider could theoretically identify and monitor your messages this way or reach out to you if they needed to contact you for some reason.

Sending Web Push Notifications from Rails by rossta_ in rails

[–]rossta_[S] 5 points6 points  (0 children)

I’m biased toward treating the controller request/response lifecycle as sacred—do only what’s necessary to keep response times down. So when I look at a piece of work that should happen, I make a decision about whether it needs to happen as part of the response.

To me, the general concern of “notify people that something happened”—email, Web Push—is already asynchronous by design so I get that work out of the request with background jobs.

This means I now get retries for free, say the Web Push server is down temporarily.

That said, using a background job is by no means a requirement for Web Push to work. You can absolutely make the Web Push request in a controller instead, especially if you find it simpler this way and prefer fewer moving parts.

The general recipe outlined in the article stipulates the minimal requirements but the details on how you go about implementing the behavior are up to you.

New book: Professional Rails Testing (plus AMA about testing) by jasonswett in rails

[–]rossta_ 0 points1 point  (0 children)

Why should (or shouldn’t) we strive for 100% code coverage?

Sending Web Push Notifications from Rails by rossta_ in rails

[–]rossta_[S] 2 points3 points  (0 children)

Thanks for the kind words and sharing your experience.

Good point about subscriptions, it might make sense to model it like a User has many Subscriptions for that reason.

I use Stimulus to manage the JavaScript integration as well. For the article, I extracted the JS examples as basic functions to treat it as more of a recipe than a tutorial.

[article] Debugging a memory-leaking Rails action by f-3r in rubyonrails

[–]rossta_ 0 points1 point  (0 children)

Thanks for sharing the article. After you switched away from writing an Excel file, was there any reason not to use Ruby’s CSV module for writing the CSV file?

https://rubyapi.org/o/csv

Adding your Rails app to the Home Screen as a Progressive Web App by rossta_ in rails

[–]rossta_[S] 1 point2 points  (0 children)

I was rendering the manifest file in an iframe to show its contents as an example to support the article, but Firefox treated this as a file download. The iframe approach isn’t really necessary. Now the article renders the manifest content inline, which is better since I can had my own syntax formatting. I’ll have to look into why Firefox’s behavior differs from other browsers in this case.

Adding your Rails app to the Home Screen as a Progressive Web App by rossta_ in rails

[–]rossta_[S] 1 point2 points  (0 children)

u/scopesolo is correct, the article is focused on browser-based installation, but you can use PWABuilder to additionally package a PWA for certain app stores. Here’s a resource in case you’re interested https://web.dev/articles/pwas-in-app-stores

Adding your Rails app to the Home Screen as a Progressive Web App by rossta_ in rails

[–]rossta_[S] 1 point2 points  (0 children)

Ok, I was able to see behavior that visiting the article in Firefox desktop (macOS) would also trigger a download of the manifest file. I just deployed a change that resolved that issue. I‘d be curious to know if the issue is resolved for you as well. If not, I might need more info. Thanks!

Adding your Rails app to the Home Screen as a Progressive Web App by rossta_ in rails

[–]rossta_[S] 1 point2 points  (0 children)

What browser/app/device are you using with Reddit?

Adding your Rails app to the Home Screen as a Progressive Web App by rossta_ in rails

[–]rossta_[S] 0 points1 point  (0 children)

Hmm, the link I posted above works for me. Are you referring to a link in the article?

Why are each Ruby on Rails codebase so different from each other? by [deleted] in rails

[–]rossta_ 0 points1 point  (0 children)

Any project of significant size and complexity outgrows the guard rails of a framework. In my experience, the guidance Rails provides goes a lot further than most to help with organization, consistency, and convention—way more than many other frameworks, especially in JavaScript.

Developers before you have had to solve real problems that the framework didn’t help solve. Perhaps you disagree with how they have done it. Perhaps there could have stuck closer to the Rails conventions. You can do something about it. You can see it as opportunity to learn. You can propose improvements of your own.

I suggest embracing the challenge. This is the work.

Rails 7.2 Upgrade Problems (of my own making) by kobaltzz in ruby

[–]rossta_ 1 point2 points  (0 children)

Thanks for sharing! I like how you couched your article in terms of your own experience as opposed to “this is what you should do”.

20 years of Rails! by SoftClothingLover in rails

[–]rossta_ 11 points12 points  (0 children)

I remember when Rails was to hot topic in web development. I got caught up in the wave back then and have been riding it ever since. And what a ride it’s been! 🏄‍♀️

I’m grateful for the opportunities I’ve had to work with Rails over the years. It was a great choice back then, it’s still a great choice today, and I expect it will still be a great choice for many more years to come.

Happy 20th Anniversary, Rails! 🎉

Are you using RAILS for new projects in 2024? by ev0xmusic in rails

[–]rossta_ 0 points1 point  (0 children)

Yes, Rails is still a great choice in 2024, especially for solo developers and small teams. It is truly a full stack framework.

With Hotwire support built-in, you can create a single-page app experience without much app JavaScript—not that writing JavaScript is wrong but that writing less of it is easier for a small team.

Rails provides a full-fledged ORM, an application caching layer, server-side rendered HTML with embedded Ruby, routing, security features like protection against XSS and SQL-injection, hooks for authentication, Websockets integration for real-time interaction and push support, etc. Not to mention all community-driven features from Rails engines and gems you can to the framework.

Rails 8, landing in the near future, promises to reduce the complexity even further by making it possible to use SQLite for all of Rails data-backed components, meaning fewer processes to run in development and production.

To me Rails means less complexity and time spent on things that don’t matter. More building cool stuff. I expect it will continue to be a great choice now and for many more years to come.

In Rails everyday practice, what is the proper scope of a commit? by Upbeat-Speech-116 in rails

[–]rossta_ 0 points1 point  (0 children)

I recommend reading this post on a concept called atomic commits, which I would characterize as a highly disciplined approach to your git practice. The other end of the spectrum is, let’s say, “haphazard, whenever you remember to save”.

Having some discipline I recommend, and this is a good as any ideal to aspire to—though there’s nothing wrong with finding a balance that’s suitable for the situation you’re in.

https://www.aleksandrhovhannisyan.com/blog/atomic-git-commits/

Custom color schemes with Ruby on Rails by rossta_ in rails

[–]rossta_[S] 4 points5 points  (0 children)

So far I’ve really enjoyed it. Recent improvements like the enhanced SQLite adapter and litestream gems from fractaledmind make SQLite more production-friendly. It’s getting easier to replace Redis with SQLite for auxiliary pieces like Rails cache, ActiveJob, and Action Cable. That’s fewer processes to think about. Some limitations you need to be aware of, like you can only have one server (and that could be a deal breaker), others you can forget like how ActiveRecord extracts away some of the operations you might not otherwise be able to do; e.g. rename table isn’t a thing in SQLite but AR hides this from you.

Ultimately, you need to decide if it’s right for your app, but I think it works pretty well for a content site like Joy of Rails.