GoRails
Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.
https://gorails.com/blog
-
Black Friday 2025 Sale
<p>I've been a bit quiet the last few months since we had our second baby on the way. Everyone's happy and healthy and I've been enjoying some time off with the family. 👨🍼</p>
<p>I wanted to share our Black Friday deals early this year since I've got my hands full with the new baby.</p>
<p>Here's what's on sale for 2025:</p>
<h3><a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">24% off the GoRails yearly plan</a> (Normally $190/year)</h3>
<p>Stay up to date with Rails 8.1, Hotwire, and more with a GoRails subscription. This works out to only $12/mo to master Ruby on Rails which is a great deal!</p>
<h3><a href="proxy.php?url=https://learnhotwire.com" target="_blank" rel="noopener noreferrer nofollow">$50 off the Learn Hotwire course</a></h3>
<p>Early this year, we launched the Learn Hotwire course and it got some incredible feedback. It's the most comprehensive and up-to-date course on Hotwire and explains how many of Hotwire's features work from scratch with plain JavaScript.</p>
<p>The Learn Hotwire course goes up in price after Cyber Monday, so be sure to snag a copy today. If you want to buy licensese for your team, send me an email!</p>
<h3><a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">$50 off Jumpstart Pro Rails, iOS and Android</a></h3>
<p>The Jumpstart Pro templates are perfect if you've got an idea or product you want to build. You can focus on building and getting your idea into users' hands as fast as possible.</p>
<p>It runs Ruby 3 and Rails 8.1, Hotwire, Stripe, and has a built-in admin interface, API, payments, teams, webhooks, API clients, and a whole slew of functionality to save you time.</p>
<p>In fact, all of our products like GoRails <a href="proxy.php?url=https://gorails.com" target="_blank" rel="noopener noreferrer nofollow">https://gorails.com</a> and Hatchbox.io <a href="proxy.php?url=https://hatchbox.io" target="_blank" rel="noopener noreferrer nofollow">https://hatchbox.io</a> run on Jumpstart Pro Rails. Since we use it every day, it's a great, battle-tested template to learn from and use as a foundation.</p>
<h3><a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=4KBO4XN" target="_blank" rel="noopener noreferrer nofollow">$50 off the Advanced Ruby: Behind the Magic course</a></h3>
<p>The Advanced Ruby course explains everything I wish I knew when I was starting my career as a Ruby on Rails developer. I struggled with learning Ruby itself because I jumped straight into the deep end with Rails. This course explains how Rails takes advantage of Ruby with DSLs, methods, classes, metaprogramming and much more. After this course, you'll have a strong understanding of how to use Ruby to build elegant software.</p>
<h3><a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=4KBO4XN" target="_blank" rel="noopener noreferrer nofollow">$50 off the Payments with Rails Master Class</a></h3>
<p>Payments have gotten very tricky to implement over the years. This course walks through accepting payments with Stripe, supporting Strong Customer Authentication, webhooks, and more.</p>
<h3><a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=4KBO4XN" target="_blank" rel="noopener noreferrer nofollow">$50 off the Refactoring Rails course</a></h3>
<p>Ben Orenstein's Refactoring Rails course is one I refer back to several times a year. It's a great set of strategies for cleaning up and better organizing your code. Highly recommend it if you want to get better at refactoring code and tests.</p>
<h3><a href="proxy.php?url=https://sellrepo.com/products/sellrepo" target="_blank" rel="noopener noreferrer nofollow">$50 off SellRepo</a></h3>
<p>SellRepo is a self-hosted, one-time purchase app (like ONCE apps) to help you sell source code. Deploy it to your server then connect your GitHub repository and Stripe account and start selling!</p>
<p>Use 7LGYNCWI at checkout to get $50 off SellRepo!</p>
<hr>
<p>Phew, that's a lot of things! If you have any questions, let me know.</p>
Thu, 13 Nov 2025 11:24:10 -0600
https://gorails.com/blog/black-friday-2025
https://gorails.com/blog/black-friday-2025
-
PostgreSQL 17 cluster config missing after upgrade on Ubuntu
<p>If you've been running PostgreSQL on your server for a while, you've been used to new versions automatically creating a default cluster. </p>
<p>When you install Postgres 16 after say Postgres 15, you'll see that it creates <code>/etc/postgresql/16/main/postgresql.conf</code> and all the other configuration files alongside <code>/etc/postgresql/15/main/</code>. Each version gets it's own default main cluster after installation. </p>
<p>But if you're using the official Postgres APT repository on Ubuntu or Debian, you may notice Postgres 17 does not do this. After installing Postgres 17, the <code>/etc/postgresql/17</code> directory is missing entirely. If you're looking for <code>/etc/postgresql/17/main/postgresql.conf</code> you won't find it. </p>
<p>Why? The PostgreSQL Debian package's postinstall script has been changed to detect existing clusters and skip creation of a new main cluster if another cluster exists. </p>
<p>Presumably, this is to help make the upgrade process simpler. If you already have Postgres 16 or lower installed, chances are you'll want to upgrade the cluster to run on Postgres 17. With this change, you no longer have to remove or rename the default main cluster for the new Postgres version during the upgrade process. </p>
<p>But if you do want to create a default main cluster for Postgres 17, you will need to run: </p>
<pre><code>$ pg_createcluster -u postgres --no-status 17 main
</code></pre>
<p>This is the same command the postgresql-17 package would run during install if no other Postgres clusters exist. You can see the new cluster by running <code>pg_lsclusters</code> </p>
<pre><code>$ sudo pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
16 main 5432 online postgres /var/lib/postgresql/16/main /var/log/postgresql/postgresql-16-main.log
17 main 5433 down postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
</code></pre>
<p>To start the new Postgres 17 cluster, you can run: </p>
<pre><code>$ sudo service postgresql start
</code></pre>
<p>You can then see that both clusters are running: </p>
<pre><code>$ sudo pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
16 main 5432 online postgres /var/lib/postgresql/16/main /var/log/postgresql/postgresql-16-main.log
17 main 5433 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
</code></pre>
<p>If you're curious about upgrading Postgres versions on Ubuntu server, take a look at our guide <a href="proxy.php?url=https://gorails.com/guides/upgrading-postgresql-version-on-ubuntu-server" target="_blank" rel="noopener noreferrer nofollow">Upgrading PostgreSQL version on Ubuntu Server</a></p>
Wed, 26 Feb 2025 16:37:05 -0600
https://gorails.com/blog/postgresql-cluster-config-missing-after-upgrade
https://gorails.com/blog/postgresql-cluster-config-missing-after-upgrade
-
Black Friday 2024 - Sales on GoRails, Courses, Jumpstart, SellRepo! 🎉
<p>Black Friday sales are a way for us to say thanks for all your support. We wouldn't be here without you! 💖</p>
<p><img></p>
<h2>Our Black Friday 2024 sales</h2>
<p><strong><a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">36% off GoRails with the yearly plan</a></strong> - <a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Get a yearly subscription to GoRails for just $144/year. That's only $12/mo to stay up-to-date with Hotwire, Rails 7, Ruby 3, and much more!</p>
<p><strong>Want to buy someone a GoRails subscription?</strong></p>
<p><a href="proxy.php?url=https://buy.stripe.com/28o9BZ2889so5Dq8wC" target="_blank" rel="noopener noreferrer nofollow">Buy a gift subscription for GoRails</a> and we'll add the subscription to their account for you.</p>
<p>You can also <a href="proxy.php?url=https://gorails.relationkit.io/tickets/new" target="_blank" rel="noopener noreferrer nofollow">send us a message</a> with the name and email of the recipient and how many months you'd like to gift them. We'll send you an invoice and once it's paid we'll invite them to their account.</p>
<p><strong><a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">$50+ off Jumpstart Pro (Rails, iOS & Android)</a></strong> - <a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Choose either the Rails, iOS, or Android template and get $50 off a single site license or $150 off an unlimited license.</p>
<p>If you're interested in building a product with Ruby on Rails, Jumpstart Pro is the perfect place to get started. We'll take care of all the ground work so you can focus on building your business. Start with Rails and when you're ready, you can expand to iOS and Android apps, or snag them now while they're on sale!</p>
<p>We built <a href="proxy.php?url=https://hatchbox.io" target="_blank" rel="noopener noreferrer nofollow">Hatchbox.io</a> using Jumpstart Pro and you can check out lots of other <a href="proxy.php?url=https://jumpstartrails.com/examples" target="_blank" rel="noopener noreferrer nofollow">Jumpstart Pro examples</a> that our customers have turned into life changing businesses.</p>
<p>iOS and Android are being updated to the brand new Hotwire Native library to take advantage of all the new goodies. We've been able to simplify a LOT of code with this upgrade too.</p>
<p></p><blockquote><p>This is wild.</p>
<p>@masilotti.com shaved off 6,000 lines of Swift code upgrading @jumpstartrails.com iOS to Hotwire Native.</p>
<p>Jumpstart Pro Rails, iOS and Android go on sale next week for Black Friday, so keep an eye out if you want to grab a copy and turn your Rails apps into native apps!<br><br><a href="proxy.php?url=https://bsky.app/profile/did:plc:bglglitlenxcnkt36zhtqic6/post/3lbmpamgjek2o?ref_src=embed">[image or embed]</a></p>— Chris Oliver (<a href="proxy.php?url=https://bsky.app/profile/did:plc:bglglitlenxcnkt36zhtqic6?ref_src=embed">@excid3.com</a>) <a href="proxy.php?url=https://bsky.app/profile/did:plc:bglglitlenxcnkt36zhtqic6/post/3lbmpamgjek2o?ref_src=embed">November 23, 2024 at 8:27 AM</a></blockquote><p></p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=EOELGJP" target="_blank" rel="noopener noreferrer nofollow">$50 off Advanced Ruby: Behind the Magic</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=EOELGJP" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>This course is everything I wish I knew about Ruby when I started as a Rails developer. We cover 6+ hours of Ruby techniques used in Rails and other Rubygems to see how they work from scratch.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=EOELGJP" target="_blank" rel="noopener noreferrer nofollow">$50 off Refactoring Rails</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=EOELGJP" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Ben Orenstein's Refactoring Rails course is one I refer back to several times a year. It's a great set of strategies for cleaning up and better organizing your code.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=EOELGJP" target="_blank" rel="noopener noreferrer nofollow">$50 off Payments with Ruby on Rails Master Class</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=EOELGJP" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Want to add Payments to your Rails app? It's gotten much trickier over the past years. This course walks you through accepting Payments with Stripe that are compatible with Strong Customer Authentication, webhooks, and more.</p>
<p><strong><a href="proxy.php?url=https://sellrepo.com" target="_blank" rel="noopener noreferrer nofollow">$50 off SellRepo</a></strong> - <a href="proxy.php?url=https://sellrepo.com" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Want to start your own business? SellRepo helps you sell source code in GitHub repositories to your audience. It is a one-time purchase so you can experiment with product ideas constantly paying fees to other platforms. You'll also get lifetime updates included. Get $50 off through Cyber Monday!</p>
<hr>
<p>If you have any questions, hit reply and let us know. 👋</p>
Mon, 25 Nov 2024 09:24:58 -0600
https://gorails.com/blog/black-friday-2024
https://gorails.com/blog/black-friday-2024
-
How to Extend the Ubuntu Default Logical Volume Partition
<p>Using VirtualBox, I'll often give Ubuntu a certain disk size and only realize later on that it isn't using the full partition size for the disk.</p>
<p>Run these commands to extend the root filesystem to use the full disk: </p>
<pre><code>lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv
df -h
</code></pre>
<p>For more details, see: <a href="proxy.php?url=https://packetpushers.net/blog/ubuntu-extend-your-default-lvm-space/" target="_blank" rel="noopener noreferrer nofollow">https://packetpushers.net/blog/ubuntu-extend-your-default-lvm-space/</a></p>
Tue, 09 Jul 2024 10:03:18 -0500
https://gorails.com/blog/extend-ubuntu-default-logical-volume-partition
https://gorails.com/blog/extend-ubuntu-default-logical-volume-partition
-
Black Friday Sale 2023!
<p>It's hard to believe it's holiday season already and 2023 is almost over. Our Black Friday sale is live and we do this every year as a way to show our appreciation for all the support the Ruby on Rails community has given us over the years. We've grown from a 1 person company to 3 to continue growing and supporting the Ruby on Rails community. Kent, Collin, and I want to say thanks for all your support that makes this possible and we promise to continue creating the best Rails education and tools we can.</p>
<p>Here are the Black Friday sales for 2023:</p>
<p><strong><a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">36% off GoRails with the yearly plan</a></strong> - <a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Get a yearly subscription to GoRails for just $144/year. That's only $12/mo to stay up-to-date with Hotwire, Rails 7, Ruby 3, and much more!</p>
<p><strong>Gifting GoRails</strong></p>
<p>Want to send someone the gift of GoRails? <a href="proxy.php?url=https://gorails.relationkit.io/tickets/new" target="_blank" rel="noopener noreferrer nofollow">Send us a message</a> with the name and email of the recipient and how many months you'd like to gift them. We'll send you an invoice and once it's paid we'll invite them to their account.</p>
<p><strong><a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">$50+ off Jumpstart Pro (Rails, iOS & Android)</a></strong> - <a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Choose either the Rails, iOS, or Android template and get $50 off a single site license or $150 off an unlimited license.</p>
<p>If you're interested in building a product with Ruby on Rails, Jumpstart Pro is the perfect place to get started. We'll take care of all the ground work so you can focus on building your business. Start with Rails and when you're ready, you can expand to iOS and Android apps, or snag them now while they're on sale!</p>
<p>We built <a href="proxy.php?url=https://hatchbox.io" target="_blank" rel="noopener noreferrer nofollow">Hatchbox.io</a> using Jumpstart Pro and you can check out lots of other <a href="proxy.php?url=https://jumpstartrails.com/examples" target="_blank" rel="noopener noreferrer nofollow">Jumpstart Pro examples</a> that our customers have turned into life changing businesses.</p>
<p>This is the time we've <em>ever</em> run a sale on Jumpstart Pro Android, so now is a great time to snag a copy if you've been waiting.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">$50 off Advanced Ruby: Behind the Magic</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>This course is everything I wish I knew about Ruby when I started as a Rails developer. We cover 6+ hours of Ruby techniques used in Rails and other Rubygems to see how they work from scratch.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">$50 off Refactoring Rails</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Ben Orenstein's Refactoring Rails course is one I refer back to several times a year. It's a great set of strategies for cleaning up and better organizing your code.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">$50 off Payments with Ruby on Rails Master Class</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Want to add Payments to your Rails app? It's gotten much trickier over the past years. This course walks you through accepting Payments with Stripe that are compatible with Strong Customer Authentication, webhooks, and more.</p>
<hr>
<p>If you have any questions, hit reply and let us know. 👋</p>
Wed, 22 Nov 2023 07:06:11 -0600
https://gorails.com/blog/black-friday-sale-2023
https://gorails.com/blog/black-friday-sale-2023
-
Rails World 2023: Powerful Rails Features You Might Not Know Talk Slides
<p>I gave a talk at Rails World 2023 in Amsterdam on Powerful Rails Features You Might Not Know. </p>
<p>If all you've got is a hammer, everything looks like a nail. In tech, there is a constant stream of new features being added every day. Keeping up with the latest Ruby on Rails functionality can help you and your team be far more productive than you might normally be.</p>
<p>In this talk, we walk through a bunch of lesser known or easy to miss features in Ruby on Rails that you can use to improve your skills.</p>
<p>And here are the slides to follow along with:</p>
Tue, 10 Oct 2023 09:01:44 -0500
https://gorails.com/blog/rails-world-2023-powerful-rails-features-you-might-not-know-talk-slides
https://gorails.com/blog/rails-world-2023-powerful-rails-features-you-might-not-know-talk-slides
-
Patching Models for Ransack 4.0.0: Extending ActiveRecord for Gem Compatibility
<p>Here at GoRails, we are running <a href="proxy.php?url=https://github.com/activeadmin/activeadmin" target="_blank" rel="noopener noreferrer nofollow">ActiveAdmin</a> to power our administration area and we recently upgraded the version which we were running to version <code>3.0.0</code>. The ActiveAdmin engine has a dependency on <a href="proxy.php?url=https://github.com/activerecord-hackery/ransack" target="_blank" rel="noopener noreferrer nofollow">Ransack</a> and along with upgrading to the latest version of ActiveAdmin that brought along an upgrade of Ransack to version <code>4.0.0</code>. </p>
<p>Going up a major version usually introduces breaking changes and sure enough this was our experience.</p>
<p>As noted in the <a href="proxy.php?url=https://github.com/activerecord-hackery/ransack/blob/main/CHANGELOG.md#400---2023-02-09" target="_blank" rel="noopener noreferrer nofollow">Ransack CHANGELOG</a> for the version <code>4.0.0</code> release there is indeed a breaking change introduced:</p>
<pre><code>Require explicit allowlisting of attributes and associations
</code></pre>
<p>So with this change indicating that we needed to explicitly denote which attributes and associations we want to allow ransack to search the thought process started. Previously, we had the ability to search all attributes of the models we pull into our admin area so while Ransack provided helpful error messages of how to implement the needed methods to explicitly list the attributes, we wanted to continue to retain the ability to search all attributes/associations used in the admin area. So what now?</p>
<p>Initially, my approach was to create a module which I could extend on the necessary models which would implement the two methods noted in the Ransack error message in the browser while running in development. The body of the methods would return an array of the attributes and associations for each model leverage some Rails methods to achieve this result. An example (but not exact) implementation of this can be seen below:</p>
<pre><code>module RansackSearchable
def ransackable_attributes(auth_object = nil)
attribute_names
end
def ransackable_associations(auth_object = nil)
reflect_on_all_associations.map { |assoc| assoc.name.to_s }
end
end
</code></pre>
<p>The initial implementation did resolve a lot of the issues encountered in most of the admin panels for most models... but not all.</p>
<p>The next issue was the fact that in our admin area we manage our tags (via ActsAsTaggableOn) for resources like this blog post, our series, and more. Additionally, We have an admin section for the Ahoy gem. These gems also needed to be extended with the above module. But how would we achieve this without re-opening the various class/modules?</p>
<p>The first thought was to switch from extending the module on the models used in the admin area and instead extend <code>ApplicationRecord</code> itself in the hopes of extending the <code>ActsAsTaggableOn</code> and <code>Ahoy</code> gems in the process.</p>
<p>Unfortunately, this didn't work as expected. After diving into the source code for the two gems, it turns out the reason this didn't happen as expected is because the <code>ActsAsTaggableOn</code> and <code>Ahoy</code> gems (engines/plugins) don't inherit from <code>ApplicationRecord</code> but instead they inherit from <code>ActiveRecord::Base</code>. So with this knowledge in place it was back to the drawing board.</p>
<p>Before taking another pass at implementing a fix, I decided to stop by the <code>ActiveAdmin</code> repository to check the issues and discussions to see if there was any talk of this issue. Sure enough, there was a great <a href="proxy.php?url=https://github.com/activeadmin/activeadmin/discussions/8033" target="_blank" rel="noopener noreferrer nofollow">discussion</a> that also had a some insight into some methods available from <code>Ransack</code> to grab the attribute names and associations in a cleaner way.</p>
<p>Now it was all starting to come together nicely, but there was still the issue of how to patch the gems.</p>
<p>Knowing that we needed to drop down a level from <code>ApplicationRecord</code> and instead extend <code>ActiveRecord::Base</code> I started to think about where a good place would be do the extending. Thinking about this more, it seemed that we would want to extend <code>ActiveRecord::Base</code> once it is loaded in our Rails application, that way the module code will be placed in the inheritance hierarchy. So creating an initializer to do this seemed like an ideal place for the code.</p>
<p>Since the module consisted of only two methods, I ultimately decided to define the module in the opening line of the initializer and then outside the module definition, and then setup an <a href="proxy.php?url=https://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html#method-i-on_load" target="_blank" rel="noopener noreferrer nofollow">on_load hook</a> for <code>:active_record</code> and inside the block passed to the hook, perform the extending. </p>
<p>Below is the final implementation that lead to a successful patch to resolve the requirement of the breaking <code>Ransack v4.0.0</code> change.</p>
<pre><code># config/initializers/ransack_patch.rb
module RansackPatch
def ransackable_attributes(auth_object = nil)
authorizable_ransackable_attributes
end
def ransackable_associations(auth_object = nil)
# The method below calls the exact code I had in my initial implementation which is: reflect_on_all_associations.map { |a| a.name.to_s }
authorizable_ransackable_associations
end
end
ActiveSupport.on_load(:active_record) do
extend RansackPatch
end
</code></pre>
Tue, 22 Aug 2023 19:50:11 -0500
https://gorails.com/blog/patching-models-for-ransack-4-0-0-extending-activerecord-for-gem-compatibility
https://gorails.com/blog/patching-models-for-ransack-4-0-0-extending-activerecord-for-gem-compatibility
-
How to test OmniAuth Params
<p>OmniAuth provides some tooling for mocking OAuth requests in your test suite. This is handy because your tests don't have to redirect to a production OAuth provider like Twitter, authenticate with real credentials, and then handle the response.</p>
<p>Instead, you can set test mode in OmniAuth and then add a mock OAuth provider. This will allow your tests to skip the production OAuth process and simulate it in your test environment.</p>
<p>One problem is testing additional params you might pass to OmniAuth. For testing, you normally just request the callback URL for the mock request. If you test only with the callback url however, the params will not be present. This is because the params are stored in the session, so you need an additional request beforehand to set those params in the session.</p>
<p>To test OmniAuth params, we need to first POST to the OmniAuth URL with params. This will make a fake request that sets the session OmniAuth params and sets a few other things. You can see exactly what it does here: <a href="proxy.php?url=https://github.com/omniauth/omniauth/blob/v2.1.0/lib/omniauth/strategy.rb#L317" target="_blank" rel="noopener noreferrer nofollow">https://github.com/omniauth/omniauth/blob/v2.1.0/lib/omniauth/strategy.rb#L317</a></p>
<p>Here's the relevant bit:</p>
<pre><code>def mock_request_call
setup_phase
session['omniauth.params'] = request.GET
# ...
</code></pre>
<p>After making the mock OAuth request, we can make the mock OAuth callback request to process it. This will now have access to <code>omniauth.params</code> in the session and we now have a functional test!</p>
<p>You can see here in the mock callback call that it sets <code>omniauth.params</code> to the params from the session:</p>
<pre><code>@env['omniauth.params'] = session.delete('omniauth.params') || {}
</code></pre>
<p>Here's an example of how to test OmniAuth params with a Rails integration test. You can use this same process to test OmniAuth params with Rspec.</p>
<pre><code>require "test_helper"
class OmniauthCallbacksTest < ActionDispatch::IntegrationTest
setup do
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:developer, uid: "12345", info: {email: "[email protected]"}, credentials: {token: 1})
end
test "can connect a social account with another model" do
# Sets omniauth.params to {"foo" => "bar"} and redirects to the OmniAuth callback URL
post "/users/auth/developer?foo=bar"
# Process the OAuth callback which has omniauth.params set
follow_redirect!
# Add your assertions here
end
end
</code></pre>
Sat, 14 Jan 2023 09:22:32 -0600
https://gorails.com/blog/how-to-test-omniauth-params
https://gorails.com/blog/how-to-test-omniauth-params
-
Bundler default gem dependency error
<p>Have you seen the following error?</p>
<pre><code>You have already activated uri 0.10.0, but your Gemfile requires uri 0.12.0. Since uri is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports uri as a default gem. (Gem::LoadError)
</code></pre>
<pre><code>You have already activated strscan 3.0.1, but your Gemfile requires strscan 3.0.2.
Since strscan is a default gem, you can either remove your dependency on it or try updating to a
newer version of bundler that supports strscan as a default gem. (Gem::LoadError)
</code></pre>
<p>I've run into this with uri, strscan, and other gems. "bundle install" works fine, but running a command like "bundle exec rails assets:precompile" fails with the error above.</p>
<p>So what gives?</p>
<h2>The Solution</h2>
<p>The issue lies with Rubygems being outdated. If you update RubyGems, it will fix the issue.</p>
<pre><code>gem update --system
</code></pre>
Fri, 06 Jan 2023 19:54:46 -0600
https://gorails.com/blog/bundler-default-gem-dependency-error
https://gorails.com/blog/bundler-default-gem-dependency-error
-
Black Friday 2022 Deals on GoRails, courses, and Jumpstart Pro!
<p>It’s Black Friday again, and this is our once-a-year sale! </p>
<p>It’s our way of saying thanks for all your support. You've been a huge part of making GoRails a success and Collin & I can't thank you enough. 🥰</p>
<p>Here's what we've got going on this year:</p>
<p><strong><a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">36% off GoRails with the yearly plan</a></strong> - <a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Get a yearly subscription to GoRails for just $144/year. That's only $12/mo to stay up-to-date with Hotwire, Rails 7, Ruby 3, and much more!</p>
<p><strong>Gifting GoRails</strong></p>
<p>Want to send someone the gift of GoRails? <a href="proxy.php?url=https://gorails.relationkit.io/tickets/new" target="_blank" rel="noopener noreferrer nofollow">Send us a message</a> with the name and email of the recipient and how many months you'd like to gift them. We'll send you an invoice and once it's paid we'll invite them to their account.</p>
<p><strong><a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">$50+ off Jumpstart Pro (Rails, iOS & Android)</a></strong> - <a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Choose either the Rails, iOS, or Android template and get $50 off a single site license or $150 off an unlimited license.</p>
<p>If you're interested in building a product with Ruby on Rails, Jumpstart Pro is the perfect place to get started. We'll take care of all the ground work so you can focus on building your business. Start with Rails and when you're ready, you can expand to iOS and Android apps, or snag them now while they're on sale!</p>
<p>We built <a href="proxy.php?url=https://hatchbox.io" target="_blank" rel="noopener noreferrer nofollow">Hatchbox.io</a> using Jumpstart Pro and you can check out lots of other <a href="proxy.php?url=https://jumpstartrails.com/examples" target="_blank" rel="noopener noreferrer nofollow">Jumpstart Pro examples</a> that our customers have turned into life changing businesses.</p>
<p>This is the time we've <em>ever</em> run a sale on Jumpstart Pro Android, so now is a great time to snag a copy if you've been waiting.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">$50 off Advanced Ruby: Behind the Magic</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>This course is everything I wish I knew about Ruby when I started as a Rails developer. We cover 6+ hours of Ruby techniques used in Rails and other Rubygems to see how they work from scratch.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">$50 off Refactoring Rails</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Ben Orenstein's Refactoring Rails course is one I refer back to several times a year. It's a great set of strategies for cleaning up and better organizing your code.</p>
<p><strong><a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">$50 off Payments with Ruby on Rails Master Class</a></strong> - <a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=GX2GK0G" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Want to add Payments to your Rails app? It's gotten much trickier over the past years. This course walks you through accepting Payments with Stripe that are compatible with Strong Customer Authentication, webhooks, and more.</p>
<hr>
<p>That's everything! I just want to say thanks for everything and allowing us to do this for a living. </p>
<p>2022 has been an exciting year and there are some secret things for 2023 that Collin & I have been working on that I can't wait to share with you soon.</p>
<p>If you have any questions, hit reply and let me know. 👋</p>
Wed, 23 Nov 2022 14:54:40 -0600
https://gorails.com/blog/black-friday-2022-deals-on-gorails-courses-and-jumpstart-pro
https://gorails.com/blog/black-friday-2022-deals-on-gorails-courses-and-jumpstart-pro
-
How To Test A Rails Rubygem Against Multiple Databases
<p>If you're building a Rubygem that integrates with Rails and ActiveRecord, you'll probably want to test against multiple databases. This is pretty easy to setup for CI where you can run multiple databases in Docker containers with different steps, but what about local development?</p>
<p>The <code>DATABASE_URL</code> is typically used for setting the production database for your Rails app. Hatchbox, Heroku, Render, etc all will set this environment variable for Rails to pick up and use the correct database.</p>
<p>You might not realize that the <code>DATABASE_URL</code> can also be used for other things like testing!</p>
<p>Instead of running <code>rails test</code> like normal, you can prepend the <code>DATABASE_URL</code> env var to change the database.</p>
<p>For example, we can change from the default database to Postgres</p>
<pre><code>DATABASE_URL=postgres://127.0.0.1/test_db rails test
</code></pre>
<p>You can even take this a step further and write a script to test each of the databases:</p>
<pre><code>#!/usr/bin/env bash
echo "Testing against SQLite3"
rails test
echo "Testing against PostgreSQL"
DATABASE_URL=postgres://127.0.0.1/test_db rails test
echo "Testing against MySQL"
DATABASE_URL=mysql2://root:@127.0.0.1/test_db rails test
</code></pre>
Wed, 30 Mar 2022 16:07:42 -0500
https://gorails.com/blog/how-to-test-a-rails-rubygem-against-multiple-databases
https://gorails.com/blog/how-to-test-a-rails-rubygem-against-multiple-databases
-
Black Friday 2021 Deals on GoRails, courses, and Jumpstart Pro!
<p>I run sales once a year on Black Friday as a way of saying thank you. You've been a huge part of making GoRails a success and I can't thank you enough. 🥰</p>
<p>Here's what we've got going on this year:</p>
<hr>
<p><a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow"><strong>36% off GoRails with the yearly plan</strong></a> - <a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Get a yearly subscription to GoRails for just $144/year. That's only $12/mo to stay up-to-date with Hotwire, Rails 7, Ruby 3, and much more!</p>
<p>If you're already subscribed to GoRails, you can upgrade from the monthly plan to lock in the savings.</p>
<hr>
<p><a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow"><strong>$50+ off Jumpstart Pro (Rails & iOS)</strong></a> - <a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Choose either the Rails or iOS template and get $50 off a single site license or $150 off an unlimited license. </p>
<p>We've never run a sale on Jumpstart Pro before so be sure to snag a copy while you can! Read on to see some exciting new updates for Jumpstart Pro that we recently launched.</p>
<hr>
<p><a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=N1LAN9L" target="_blank" rel="noopener noreferrer nofollow"><strong>$50 off Advanced Ruby: Behind the Magic</strong></a> - <a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs?coupon=N1LAN9L" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>This is also the first time I've discounted the Advanced Ruby course! This course is everything I wish I knew about Ruby when I started as a Rails developer. We cover 6+ hours of Ruby techniques used in Rails and other Rubygems to see how they work from scratch.</p>
<hr>
<p><a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=N1LAN9L" target="_blank" rel="noopener noreferrer nofollow"><strong>$50 off Refactoring Rails</strong></a> - <a href="proxy.php?url=https://courses.gorails.com/refactoring-rails?coupon=N1LAN9L" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Ben Orenstein's Refactoring Rails course is one I refer back to several times a year. It's a great set of strategies for cleaning up and better organizing your code.</p>
<hr>
<p><a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=N1LAN9L" target="_blank" rel="noopener noreferrer nofollow"><strong>$50 off Payments with Ruby on Rails Master Class</strong></a> - <a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class?coupon=N1LAN9L" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Want to add Payments to your Rails app? It's gotten much trickier over the past years. This course walks you through accepting Payments with Stripe that are compatible with Strong Customer Authentication, webhooks, and more.</p>
<hr>
<p>That's everything! I just want to say thanks again for everything and allowing me to do this for a living. 2021 has been a crazy year and there are some secret things I've been working on that I can't wait to share with you soon.</p>
<p>If you have any questions, hit reply and let me know. 👋</p>
Tue, 23 Nov 2021 22:17:50 -0600
https://gorails.com/blog/black-friday-2021-deals-on-gorails-courses-and-jumpstart-pro
https://gorails.com/blog/black-friday-2021-deals-on-gorails-courses-and-jumpstart-pro
-
How to render ActionText Attachments in Plain Text
<p>ActionText supports custom attachments using Signed Global IDs. We can use this to embed any database record in Rails such as @mentions for users.</p>
<p>For HTML, Rails will use the <code>to_partial_path</code> to render the HTML template for the attachment. For a user, this would be <code>app/views/users/_user.html.erb</code>.</p>
<p>With Plain Text output, Rails will default to the caption specified on the attachable. Typically, this is nil because we don't need a caption for an @mention.</p>
<p>By defining the <code>attachable_plain_text_representation</code> method, we can specify the default value for the plain text ActionText output.</p>
<pre><code>class User
include ActionText::Attachable
# When ActionText rendering mentions in plain text
def attachable_plain_text_representation(caption = nil)
caption || name
end
</code></pre>
<p>And that's it! Simply render your ActionText content as plain text and it will use this method for rendering.</p>
Tue, 02 Nov 2021 10:12:26 -0500
https://gorails.com/blog/how-to-render-actiontext-attachments-in-plain-text
https://gorails.com/blog/how-to-render-actiontext-attachments-in-plain-text
-
How to use Partials in Rails
<p>If you want to keep your code simple and/or reuse a block of code in multiple files, then you can store that code in an html.erb file called a partial.</p>
<p>Create partial 🧩 </p>
<ol>
<li>Go to app > views.</li>
<li>Create a folder called shared.</li>
<li>Create a file to store your code in and name it using the syntax: _[partial].html.erb
Insert partial ⬇️</li>
</ol>
<p>In the file where you want to include the code from a partial, insert the tag<br>
<code><%= render partial "shared/</code><code>[partial]</code><code>%></code></p>
<p>View page 👀 </p>
<p>You’ll see your page with the code from the partial included.</p>
Tue, 23 Feb 2021 15:38:18 -0600
https://gorails.com/blog/how-to-use-partials-in-rails
https://gorails.com/blog/how-to-use-partials-in-rails
-
How to add a Root Route to your Rails app
<p>You need to replace the default, “Yay! You’re on Rails” landing page with a real index page for your app.</p>
<p>Create a route 🛤️ </p>
<ol>
<li>Go to config > routes.rb file</li>
<li>In the Rails.application.routes.draw method, enter the route:
<code>get root, to:</code> <code>"</code><code>main#index</code><code>"</code></li>
</ol>
<p><img></p>
<p>Create a controller 👨✈️ </p>
<ol>
<li>Go to app > controllers folder</li>
<li>Create a file named <code>main_controller.rb</code></li>
<li>Create a class named <code>MainController</code> and inherit from <code>ApplicationController</code></li>
<li>Define a method named <code>index</code>.</li>
</ol>
<p><img></p>
<p>Create a view 🏞️ </p>
<ol>
<li>Go to app > views folder</li>
<li>Create a folder named <code>main</code></li>
<li>In that folder create a file named <code>index.html.erb</code></li>
<li>Add HTML</li>
</ol>
<p><img></p>
<p>View new page 👀 </p>
<ol>
<li>Go to <a href="proxy.php?url=http://localhost:3000" target="_blank" rel="noopener noreferrer nofollow">http://localhost:3000</a></li>
<li>You’ll see the new page</li>
</ol>
<p><img></p>
Tue, 23 Feb 2021 15:37:51 -0600
https://gorails.com/blog/how-to-add-a-root-route-to-your-rails-app
https://gorails.com/blog/how-to-add-a-root-route-to-your-rails-app
-
How to add a Page to your Rails app
<p>⚠️ This is how to add a page without any interaction with the model.</p>
<h2>Create a route 🛤️</h2>
<ol>
<li>Go to config > routes.rb file</li>
<li>In the Rails.application.routes.draw method, enter a route using the syntax:
[request type] "[URL]", to: "[controller]#[action]"
<img></li>
</ol>
<p>Create a controller 👨✈️ </p>
<ol>
<li>Go to app > controllers folder</li>
<li>Create a file named [route]_controller.rb, e.g. about_controller.rb</li>
<li>Create a class named [Route]Controller and inherit from ApplicationController</li>
<li>Define a method named [action from routes.rb], e.g. index
<img></li>
</ol>
<p>Create a view 🏞️ </p>
<ol>
<li>Go to app > views folder</li>
<li>Create a folder named [route]</li>
<li>In that folder create a file named [action.html.erb]</li>
<li>Add HTML (and ERB)
<img></li>
</ol>
<p>View new page 👀 </p>
<ol>
<li>Go to <a href="proxy.php?url=http://localhost:3000/about" target="_blank" rel="noopener noreferrer nofollow">http://localhost:3000/about</a></li>
<li><p>You’ll see the new page<br>
<img></p></li>
<li><p>Open Web Inspector<br>
👀 You’ll see the request from the browser and the response from the server for the GET request to the /about URL.<br>
<img></p></li>
<li><p>View the page’s source code<br>
👀 You’ll see the content that Rails added code from app > views > layouts > application.html.erb and inserted the code from index.html.erb inside the <%= yield => ERB tag.<br>
<img></p></li>
</ol>
<p><img></p>
Tue, 23 Feb 2021 15:37:06 -0600
https://gorails.com/blog/how-to-add-a-page-to-your-rails-app
https://gorails.com/blog/how-to-add-a-page-to-your-rails-app
-
How HTTP Requests work in Rails
<h2>Process overview</h2>
<p>⚠️ This is how HTTP requests work without any interaction with the model.</p>
<p>[request] ➡️ routes.rb ➡️ [controller] + [action] ➡️ view ➡️ browser</p>
<ol>
<li>A browser sends an HTTP <a href="proxy.php?url=e.g.%20/about" target="_blank" rel="noopener noreferrer nofollow">request</a></li>
<li>The Rails server receives the request</li>
<li>routes.rb tells Rails which [controller] + [action] to send the request to (e.g. about#index)</li>
<li>The [controller] receives the request and runs code in the method that matches the [action] from routes.rb</li>
<li>Rails generates a view (e.g. index.html.erb)</li>
<li>Rails sends the view back to the browser</li>
<li>The browser renders the view</li>
</ol>
<p><img></p>
<p>⚠️ A model is included in later guides.</p>
<p>🔗 <a href="proxy.php?url=https://thoughtbot.com/upcase/videos/rest" target="_blank" rel="noopener noreferrer nofollow">Link</a> to REST tutorial via Thoughtbot</p>
Tue, 23 Feb 2021 15:36:19 -0600
https://gorails.com/blog/how-http-requests-work-in-rails
https://gorails.com/blog/how-http-requests-work-in-rails
-
Black Friday 2020 Deals
<p>This is a special time of the year to give back to the Ruby on Rails community. You have so wonderful and supportive of GoRails. 🤗</p>
<p>I'm running a big sale across all the GoRails products this year. I only do this once a year so if you're thinking about grabbing a GoRails subscription, Jumpstart Pro, or one of my courses, grab it now! <strong>Deals end on November 30th, 2020.</strong></p>
<hr>
<p><a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow"><strong>36% off GoRails with the yearly plan</strong></a> - <a href="proxy.php?url=https://gorails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>You can get a yearly subscription to GoRails for just $144/year. That's $12/mo to keep up-to-date with the latest Ruby on Rails features, learn testing, and how to build features for your products.</p>
<p>If you're already subscribed to GoRails, you can upgrade from the monthly plan to lock in the savings.</p>
<hr>
<p><a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow"><strong>Buy Jumpstart Pro and get 3 free months of Hatchbox.io</strong></a> - <a href="proxy.php?url=https://jumpstartrails.com/pricing" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Jumpstart Pro is a pre-built Ruby on Rails application template that comes with Authentication, Teams, Payments (with Stripe SCA support), an API, and <em>a ton</em> of other features ready out of the box.</p>
<p>We know hosting can be expensive when you're spending your savings trying to launch a production idea. That's why we're bundling 3 months of <a href="proxy.php?url=https://hatchbox.io/" target="_blank" rel="noopener noreferrer nofollow">Hatchbox.io</a> so you can deploy your apps without worrying about hosting costs eating into your rent money.</p>
<p>In 2021, we'll be working on Jumpstart Pro to include updates for the new Turbolinks and Stimulus changes coming soon. Since we have a lot of ongoing maintenance, I'm going to change the pricing to start charging for yearly updates with new customers in the future. Now is a great time to buy Jumpstart Pro and be grandfathered in for free updates for your license forever!</p>
<hr>
<p><a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class" target="_blank" rel="noopener noreferrer nofollow"><strong>$50 off Payments with Ruby on Rails Master Class</strong></a> - <a href="proxy.php?url=https://courses.gorails.com/payments-with-rails-master-class" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>I recently launched the new Payments with Ruby on Rails master class with updates for the all new Stripe APIs. If you need to add Strong Customer Authentication for payments in your application, now's the time to buy the course. I spent 3 months learning and implementing the Stripe changes for SCA so you don't have to.</p>
<p>The price goes up to $149 after December 2nd, so make sure to snag the course while you can.</p>
<hr>
<p><a href="proxy.php?url=https://courses.gorails.com/refactoring-rails" target="_blank" rel="noopener noreferrer nofollow"><strong>$50 off Refactoring Rails</strong></a> - <a href="proxy.php?url=https://courses.gorails.com/refactoring-rails" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>Ben Orenstein (who you probably know from Tuple.app and expert Vim skills) teaches a wonderful course on the refactorings, patterns, and best practices that will let you ship quickly even as your Rails app matures.</p>
<p>I personally went through this course and regularly reference it when I refactor my code.<br>
</p>
<hr>
<p><a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs" target="_blank" rel="noopener noreferrer nofollow"><strong>Private Livestreams for Advanced Ruby: Behind The Magic students</strong></a> - <a href="proxy.php?url=https://courses.gorails.com/advanced-ruby-for-rails-devs" target="_blank" rel="noopener noreferrer nofollow">Get the deal</a></p>
<p>I wanted to do something special for the Advanced Ruby course since it is BRAND NEW! This course covers <em>tons</em> of techniques that the Rails core team and gem developers use to build fantastic libraries in Ruby. These are things you won't typically see in day-to-day Rails code, but knowing these things can drastically improve your Ruby code (whether it's in a Rails app or not).</p>
<p>For Black Friday, I'm doing several private livestreams exclusively for Advanced Ruby students. I'll be answering questions, refactor Ruby snippets with you, and most importantly I will show you how to apply these techniques in a real example: the Pay gem.</p>
<hr>
<p>That's everything! 2020 has been a hard year and I wanted to say thanks for your support. I'm incredibly fortunate to be able to do this for a living. Thank you so much for making that possible!</p>
<p>If you have any questions, send me an email at chris @ gorails dot com</p>
Wed, 25 Nov 2020 22:53:51 -0600
https://gorails.com/blog/black-friday-2020-deals
https://gorails.com/blog/black-friday-2020-deals
-
Dynamic Footer Timestamp in Rails
<p>Ever seen the typical copyright message at the bottom of a website that's out of date? Yep. A surprising amount of websites have them!</p>
<p><code>© 1992 Your Company</code></p>
<p>Someone just hard coded the year and called it a day.</p>
<p>That's fine and dandy and it's not hard to change, but it's easy to forget you need to update it.</p>
<p>A better solution? Use Rails to dynamically generate it.</p>
<p><code>© <%= Date.current.year %> Your Company</code></p>
<p>This will always print the current year in your footer. We use <code>Date.current</code> because we're using Rails and this method will take into account the current time zone in Rails. </p>
<p>You can also use <code>Date.today.year</code> to use pure Ruby, but this won't apply the current time zone to the calculation. </p>
<p>Either way, this is will display the current year from the server side and will always be accurate.</p>
<p>An alternative is to use client side Javascript for this, but it will instead use the browser's timezone so it will display the year in their time zone. </p>
<p><code>© <script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script> Your Company</code></p>
Tue, 31 Dec 2019 12:26:40 -0600
https://gorails.com/blog/dynamic-footer-timestamp-in-rails
https://gorails.com/blog/dynamic-footer-timestamp-in-rails
-
Limit Webpacker RAM on compile for production
<p>If you're deploying Rails to production with Webpacker, you might run into a Compilation failed error from Webpacker. </p>
<p>Often this happens because Webpacker runs out of RAM and the operating system kills the command for using too many resources. Modern VPS servers run on SSDs and don't enable a swap file by default because it can cause additional wear on the SSD and significantly reduce the lifetime of the drive. A side effect of this is the operating system is more aggressive with killing processes when it runs out of RAM.</p>
<p>To confirm this is your problem, you'll want to make sure that compiling assets doesn't throw any errors because of broken code. Update <code>config/webpacker.yml</code> to have <code>webpack_compile_output: true</code> and redeploy. If you are getting an error now, then you probably just need to fix that and you aren't running out of RAM.</p>
<p><em>Getting the "Compilation failed" error from Webpacker?</em></p>
<p>Try setting NODE_OPTIONS="--max-old-space-size=350" in your environment variables.</p>
<p>What this will do is tell Node.js that it can only use up to 350MB of RAM. This applies to your yarn install and webpack compile steps and will force it to run within those limits.</p>
<p>If you set this number too low, you'll get an error that Node.js was unable to allocate memory. You can try raising the max-old-space-size number until your compiles are working again. </p>
<p>This is really helpful if you're compiling webpack assets on a 1GB of RAM server and already have Rails, Sidekiq, Postgres, Redis, etc running. The free RAM will only be a portion of the 1GB left, so in our case, we could set it to 350MB of RAM to keep the OS from killing our webpack precompile.</p>
Thu, 12 Dec 2019 08:44:46 -0600
https://gorails.com/blog/limit-webpacker-ram-on-compile-for-production
https://gorails.com/blog/limit-webpacker-ram-on-compile-for-production