Tag: Ruby on Rails

  • Show a devise log in or sign up forms in another page

    This is an update of an old post of similar name but for a newer version of Devise and with better design decisions. The old post was for Devise 1.0.8, this one covers 4.0.0 I was trying to have a single page with both sign in and sign up forms with Devise 4.0.0 but this […]

  • Run bundler-audit during testing

    Run bundler-audit during testing

    There’s a gem called bundler-audit that checks whether any of the gems in your project have open security advisors against them. A year or so ago there was an infamous month in which Rails itself got three of those. It was terrible and I think bundler-audit is a good idea. My only problem with it […]

  • random_unique_id version 1.0.0 released

    random_unique_id version 1.0.0 released

    The core of random_unique_id was developed for Watu very early on, which means that it has been used in production for more than two years and a few thousands millions of records. It’s been released as a gem and we had a few iterations. It has 100% code coverage, code climate rating 4.0, 100% documentation coverage, a […]

  • Making your app work with no data

    Most applications, web, desktop or mobile, handle some kind of data. When we are developing them we generally generate some sample data to play with and we forget to ever run the application without it. The problem is that the first impression people will get of our app is without data. And first impressions are […]

  • Full URL in Rails’ logs

    I find myself needing to have the full URLs in Rails’ logs. Normally you get something like: but I needed because the app does different things depending on the domain and when it fails, I have to know which URL was hit. The solution I ended up with was adding this in an initializer: That’s […]

  • Getting rid of RubyGems deprecation warnings

    A recent update to RubyGems is causing a lot of deprecation warnings like these: I generally like software to move forward and the way to do that is deprecate and then after a while, make backwards incompatible changes. It’s painful but there’s no other way. I do have a problem with all the cron jobs […]

  • Careful with that email

    When you are building systems like my Keep on Posting or my DNSk9 that send emails there’s always the danger that you’ll accidentally fire emails from your development machine to real users. You really don’t want to do that because it’s annoying and extremely unprofessional. It happened to me a couple of times. Thankfully, nothing […]

  • Rake tasks for production

    When I need to run something periodically on production, I always implement it as a rake tasks and install it as a cron job. Nevertheless there’s some setup to do in the task to have proper logging and error reporting. This is the template I use for creating those tasks: namespace :projectx do desc “Do […]

  • Another useful collection method? Enumerable#select_first

    For a personal project I’m working on, I need to find out the smallest time period with more than 5 records. I essentially wrote this code: period = [1.week, 1.month, 1.year].select_first do |period| Record.where(“published_at >= ?”, period.ago).count >= 5 end only to find out that the select_first method doesn’t exist. So I wrote it: module […]

  • Metaprogramming Ruby

    Metaprogramming Ruby

    There are thousands of books that will take you from illiterate to novice in any programming language. But finding those that will take you from novice or intermediate to expert is hard. I remember reading Effective Java some years ago and wishing I had something like that for Python. I’ve never found one. Metaprogramming Ruby […]