Rails engines range from simple plugins to powerful micro-applications. The discussions we’ve had so far about Railties are closely related to the function of a Rails engine. One interesting side note is that a Rails application is a Rails engine itself — so it’s easy to see how we can encapsulate just about any normal Rails functionality in an engine, to ultimately embed in a host application.
The Rails engine documentation is well written and touches on the many ways to include functionality. I won’t cover every detail of Rails engines in this chapter, just enough to get you started making use of them. It’s possible to make full applications (routes, controllers, models, migrations, etc.) using Rails engines. However, we’re going to focus on some of the simpler the elements of a Rails engine that allow us to integrate functionality where a Railtie won’t suffice. Just know, there is far more you can do with Rails engines than what we’ll cover here. The documentation link above provides examples of many of those use cases.continue reading →
I spent the last couple of weeks with my head down focusing on producing the best content possible for the upcoming release of my Build a Ruby Gem ebook. I’m excited to finally show you what I’ve been working on.
The book will be available starting at Midnight (EDT) on Thursday, March 27th and can be purchased from my website.continue reading →
The world isn’t black and white (as much as we’d like to believe it is). Just because our gem’s functionality may work for us, doesn’t mean it’ll work for everyone.
Fortunately, we can give users the ability to add custom configuration data, allowing them to adapt our code to their own use. In this post, we’ll adapt the
mega_lotto gem to take a configuration block that modifies the number of integers returned from the
#draw method output.
One of the simplest and most common application of background processing is sending emails outside of a web request. And while background processing is pretty common, most existing Ruby background processing libraries require an additional process to execute these jobs, resulting in increased infrastructure costs.
At the time, I was working on an application hosted on Heroku, and the cost of an additional dyno ($35/month) wasn’t justified. The background jobs did very little more than send emails out of band. To me, the traditional solutions seemed like overkill. And with this, the idea of sucker_punch was born…continue reading →
Greetings from a now less snowy Eastern USA!
The past few weeks have seemed like one big snow storm. We haven’t had many days above freezing and spent very little time outside (voluntarily at least). I’m sure those living in colder climates are probably saying “cry me a river…” right now. On the bright side, our extended home stays have given me more time to write.continue reading →
Last week, I was looking through my Twitter stream and came across a tweet that referenced
ENV[“RAILS_CACHE_ID”]. I was unfamiliar with this environment variable and made a note to learn more.
Rails 4 has made a discernible effort to improve view rendering performance by what they’re calling russian doll caching. Prior to this, view caching was simple in syntax, but realistically more complicated when cached partials needed busting on subsequent releases.continue reading →
This past weekend I added ~ 6,000 words to the existing content. I’m really excited to be nearing the end of the road. I’ve gotten some great feedback since I started and wanted to gather a bit more to finalize the chapter list.
Here’s the chapter list I’m working with so far:continue reading →
Imagine you have 2 pages in your application (landing and contact) and need an alert box to show up on the contact page only. How would you do it?continue reading →
Facebook’s news feed popularized the relative timestamp format of “X hours ago”. For good reason too…why print an absolute timestamp so that people have to do the relative calculation in their head? It’s one less step for the user, and to be fair, pretty easy to implement.
Rails helpers to the rescue
Rails has a view helper aptly named
time_ago_in_words. If you use the
created_at attribute from a record, you could easily reference a relative timestamp from a corresponding view:
# app/views/posts/show.html.erb Posted: <%= time_ago_in_words(post.created_at) %> ago
That’s great! But not enough…what happens when a user stays on the page for 10 min. and the latest post was no longer posted “1 minute ago”? Asking them to refresh the page every 10 minutes is no longer an acceptable answer.continue reading →