Previously, I outlined the new hotness that is Hotwire. New features are nice, but what can you build with it? Let's build a little project, and let's make it something different from the usual Twitter clone that's being used to demonstrate this new feature. Instead, I'll show how to build a basic scrolling price ticker like you'd see on any stock site that updates in real time. We'll learn a few interesting things along the way.Read more »
Articles about Rails
Have you ever had to deal with complex forms creating multiple objects and hierarchies in one request? Rails is there to help provide a set of helpers, methods and conventions to build nested forms, handle assignment, and creation of the objects involved in only a few lines of code. In this blog I'll explain how that works using
fields_for, strong parameters and more.
Some time ago we wrote an article to explain how to implement Stripe Connect in a Rails application. That article covered mainly the connection part between Rails and Stripe. This one will cover the fun part, which is making transactions, charges, refunds, and more.
If you haven't checked out the first part yet I recommend you do so since this article will continue from where that one ended.Read more »
Service Objects are a controversial idea for several different reasons: some developers like to use them, others like to use similar patterns, and some think that they are just unnecessary because they prefer fat models.
Here at OmbuLabs we like to use service objects whenever we can, we think it's a great way to keep our controllers skinny.
In this post I would like to discuss my idea about service objects and why it's adopted by our team.Read more »
The goal of this integration was to sync data between the Rails app and the Bitrix CRM. Basically we wanted to pull data from Bitrix every time there was a change (i.e. Lead was created/updated). We also wanted to sync the other way around, push changes to Bitrix every time something changed on the Rails side.Read more »
In a previous article we talked about one of the Rails Girls events that we sponsored and co-organized in 2018. Fast forward one year to our first event of 2019 at A3, a new coworking space located in Buenos Aires, we were once again sponsors and volunteers at another successful Rails Girls event.Read more »
One of the first complications that most webapps of any complexity will run into is the need for privileged users who can do things that normal users can't or shouldn't be able to do. Before too long, you're headed towards writing your very own administrative interface. This is not only extra work, but can be tricky to do without compromising the security of the application you're administering. Most Rails developers will be familiar with this story, and Rails being Rails, it turns out that there are a couple of good options for extending your existing applications with a pre-generated, customizable admin console.Read more »
In a recent project for OmbuLabs, we were looking for a payment solution that allows users of our platform to easily start accepting online payments while at the same time allowing us to collect a fee from each transaction they receive. That's where Stripe Connect came into place.Read more »
At OmbuLabs, we are big fans of Ruby on Rails and design patterns, especially convention over configuration! The beauty of Rails is that you can inherit a legacy project and easily find the different layers of code in different directories.
When it comes to database migrations the policy of Rails is very clear. It's all about altering the database structure with gradual migration files: "Migrations are a convenient way to alter your database schema over time in a consistent and easy way." (source)
But, what about data migrations? What's the best way to write, maintain, and run migrations that alter the data in your production database?
In this article I will talk about three different patterns for writing and maintaining your data migrations:
- Data migrations in
- Data migrations with a set of Rake tasks
- Data migrations with
In this article we are going to focus on a common scenario when using those services: How can we have a real time status of the emails and text messages that we send from our Rails app.Read more »
If you are interested in Ruby and Rails performance, you have definitely read articles by Nate Berkopec from Speedshop. At Ombu Labs we are big fans of his work, his Complete Guide to Rails Performance book and Slack community.
When Nate announced a series of public workshops I didn't hesitate and signed up as quickly as possible. Here are my notes from my experience at the workshop on October 17th.Read more »
The internet is a wonderful place, but there will always be people that don't have good intentions when they visit our websites. That's why you need to be aware of the vulnerabilities that your application can have and how to avoid them. In this article I'll cover two common security problems in Rails applications (I'll probably make a second part since this is a very extensive topic).Read more »
Hello and welcome to the first OmbuCast by OmbuLabs. In this screencast we'll
be taking a look at the
and how you can use it to benchmark your Rails application and find, and
hopefully fix bottlenecks in your code.
Last month was the fifth edition of the Rails Girls Buenos Aires event, and the third time OmbuLabs participated as a sponsor and part of the coaching team. This time it took place in the impressive offices of Google Argentina where 25 participants attended. All of them were very excited and motivated to start learning new skills.Read more »
Today we are happy to announce the launch of our first productized service: FastRuby.io - Speedy Ruby on Rails Upgrades by OmbuLabs.
We are quite familiar with this sort of projects and decided to package it under its own domain. We have been doing Ruby on Rails upgrades since 2009, for our own products and client projects, and we are looking forward to shipping more of them.Read more »
I have been using the capybara-webkit gem for a while now since I first tried it out after making the switch from Capybara + Selenium.
Using capybara-webkit speeds up my Selenium tests due to its headless nature, and it's very straightforward. However, I had some trouble testing a Rails based React app.
In this post, I will explain how I worked around the issues that came up when trying to use capybara-webkit with React.Read more »
Be it for performance or for readability, sometimes it's nice to be able to try out something new quickly without going through a pull request + deployment process. This is possible by modifying the $LOAD_PATH Ruby global variable and requiring the gem manually.Read more »
When working on a Rails project, you may have seen
present? calls on
ActiveRecord relationships. This might feel natural, mostly because
exists on all objects via ActiveSupport, so you expect the relationship to respond to it,
but it's actually not a very good idea. If all we want to do is check if the
scope returns any results from the database, there are better ways than using
I'm a big fan of having small classes. I'm not a big fan of having huge specs for a small class/object. Every time I see an opportunity to DRY my specs, I take it.
Today I wrote a spec to make sure that we gracefully ignore SPAMmy contact requests in the OmbuLabs contact page. It initially looked like this:
test "gracefully ignores spammy requests with valid attributes" do @valid_contact = contacts(:two) attributes = @valid_contact.attributes .merge(email_confirmation: @valid_contact.email) assert_no_difference("Contact.count") do post :create, contact: attributes, format: 'js' end assert_response :success end
The new behavior adds a simple SPAM trap field
that bots will usually fall for.
If a bot is submitting the
email_confirmation field (which is hidden by a CSS
class), then it is SPAM and it gracefully ignores the request.
Sessions provide you a nice little data storage feature where the application does not need to get the information directly from the database. So you do not have to persist data in your database and can easily store info about the user on the fly. This is a nice way to enhance the user experience on your page.
Let's say that you want to show some users a new fancy sign up form and the rest the old form. If you store the version of the sign up form in a session variable, you don't need to persist this info in your database.Read more »
Recently, we started using Skylight in production for one of our clients' Rails applications, in an attempt to try to improve the performance of some of the more critical API endpoints.
Skylight reports on:
- Time taken per request
- Breakdown of time taken per SQL query
- Object allocations per request
I noticed an unusually large amount of allocated objects for one request:
This request would take anywhere from 400ms to 3000ms to respond, which is WAY too long.Read more »
It will come a time when you will have to decide whether to maintain a Rails project or not.
If you want to seriously consider it, you should follow these 10 steps:
1. Setup the development environment
Git clone the repository and try to start the server. Is the
README clear enough? Can you follow the steps in the file and easily get started?
A lot of projects will have a
README that is out of date and/or instructions that don't work right off the bat.
Most of the projects will define guidelines like these:
- Configure your
- Configure your
- Setup the database
rake db:create db:migrate db:seed
- Start the server
The best projects will have a one-liner that will setup the entire environment for you.Read more »
Maybe in the past you stumbled over the two different approaches to setup your test variables. One way is the more programmatical approach by using instance variables, usually initialized in a
The CSRF Protection secures your app with a token. Rails makes sure that the person who is interacting with your app is someone who started a session in your site, not some random attacker from another site. So you should not turn it off, unless you know what you are doing.Read more »
Read more »
default_scope is a method provided by ActiveRecord, which allows you to set
a default scope (as its name implies) for all operations done on a given model.
It can be useful for allowing soft-deletion in your models, by having a
deleted_on column on your model and setting the default scope to