In July of 2017, CircleCI released their new platform, 2.0. It’s much more powerful and flexible, but it’s also more complex to get up and running with for Rails apps. Let’s walk through it… A Base Configuration The CircleCI configuration file is now in .circleci/config.yml. Initially, it should start looking something like this: --- version: 2 jobs: build: working_directory: ~/your-app-name steps
Requests to external services during test runs can cause several issues: Tests failing intermittently due to connectivity issues. Dramatically slower test suites. Hitting API rate limits on 3rd party sites (e.g. Twitter). Service may not exist yet (only documentation for it). Service doesn’t have a sandbox or staging server. When integrating with external services we want to make sure our test sui
Chances are, some of you have run into the issue with the invalid byte sequence in UTF-8 error when dealing with user-submitted data. A Google search shows that my hunch isn’t off. Among the search results are plenty of answers—some using the deprecated iconv library—that might lead you to a sufficient fix. However, among the slew of queries are few answers on how to reliably replicate and test th
About a year and a half ago we built an internal tool for company-wide announcements. We had originally built the back-end in Phoenix and the front-end in React, taking advantage of Redux and Phoenix channels to deliver updates to the browser in real-time. This made for a great real-time experience but it also slowed down the pace of development and caused fewer people to contribute. About three m
Navigation > > visit visit visit navigates to a particular path. Pass a string or use one of Rails’ path helpers. visit '/blog' visit blogs_path > > click_on click_on click_on will click an anchor tag, button, or input with type submit. Pass a string containing the anchor text. click_on 'Sign in' click_on 'Submit' Page Interaction and Scoping > > has_css? has_css? has_css? returns a boolean value
Administrate is a new open-source library that helps you create beautiful admin dashboards in Rails apps. thoughtbot builds applications for all kinds of clients. No matter what field our clients are in, one of the most common needs is an admin dashboard - a window into the data behind the application. In those situations, we historically turned to the excellent Ruby gems Active Admin and RailsAdm
You are a developer for startup called Movie Social Network++, building a social network for movie aficionados. Several features are dependent on data about various movies, actors, or directors. You do a quick Google search to figure out where to get this sort of data and come across movie-facts.com. They have already gathered all this data and have a team constantly keeping it up to date. They of
While converting Clearance to a Rails engine was easy, once we were there, we found it wasn’t Valhalla. We fixed the bugs while using the engine internally on a few apps. Here are the lessons we learned. Keep them in mind if you’re thinking of writing your own engine. Routes precedence As developers, we want routes in our app to take precedence over routes in the engine. That is not the default be
Have you ever noticed that when you assign a property to an Active Record model and read it back, the value isn’t always the same? Here’s an example: class StoreListing < ActiveRecord::Base connection.create_table :store_listings, force: true do |t| t.integer :price_in_cents end end store_listing = StoreListing.new store_listing.price_in_cents = "100" # Note, this is a string store_listing.price_i
Your Rails application probably makes use of uniqueness validations in several key places. This validation provides for a nice user experience when duplicate records are detected but as we will see in a moment, is not enough to ensure data integrity. What Can Go Wrong Let’s take a look at our sample User class. When you persist a user instance, Rails will validate your model by running a SELECT qu
Every developer runs into the dreaded nil object error: NoMethodError in Ruby, AttributeError in Python, and NullPointerException in Java. These errors are one of the largest sources of bugs. Even most static languages allow nil objects to silently pass as any type of object, and it’s just as easy in Ruby to let a nil object slip into seemingly well-factored code. If this is such a widespread and
if object.kind_of?(User) do_this else object.do_that end Why not? Because Ruby encourages duck typing and polymorphism. A hidden version Here’s the same principle: This checks that object is of type NilClass instead of type User. The pattern There’s an old pattern called Null Object that addresses this special case of avoiding type-checking in favor of duck typing. Here’s an example of the “Introd
Do you realize how much time you’ve spent running bundle install? ] No more sword fighting! Bundler 1.4.0 adds support for parallel installation. You can pass in --jobs SIZE as a parameter to bundle config1. I recommend setting the size to one less the number of CPU cores on your machine2. But Prem, how much time could I save Let’s benchmark this! I’m going to run bundle install on a freshly-creat
As Rails developers, we run into Sinatra apps all the time: gems such as Resque which expose a dashboard via Sinatra, legacy Sinatra apps that run alongside a main Rails app, and Sinatra APIs embedded within a Rails app, to name a few examples. Here’s a common problem: how do you share authentication between the apps? It would be really convenient to be able to do something like this in our Sinatr
We’re pleased to announce Hound, a hosted service that comments on Ruby style guide violations in your GitHub pull requests. Hound is currently free and available for public and private GitHub projects. We intend to charge in the near future to ensure Hound is sustainable, but public projects will continue to be free. Hound is also open source. Why code style matters At thoughtbot, we write code t
We partner with organizations of all sizes to design, develop, and grow their products for iOS, Android, and the web. This is our Playbook. We are thoughtbot. We have worked with hundreds of product teams all over the world, from individual founders who are self-funded, to large multi-national organizations to design, develop, and grow their products. We have also created our own products and doze
# app/models/user.rb class User < ActiveRecord::Base has_secure_password has_many :posts end # app/models/post.rb class Post < ActiveRecord::Base belongs_to :user end # app/controllers/posts_controller.rb class PostsController < ApplicationController def show @post = Post.find(params[:id]) render json: @post.as_json( only: [:id, :content, :created_at], include: { user: { only: [:id, :username] } }
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く