Influenced by the experiences I’ve had last ten years of building and maintaining Rails applications, combined with my experiences using other technologies, I’ve developed some ways of structuring Rails applications that have worked out pretty well for me.
While building applications in Rails it’s very common to have to add a new model after you’ve already set up a DB and added some seed data. So, what do you do when you need to inject data into the new model, but dont want to drop the whole data base?
My rails version: Ruby Version: 2.7.1p83 I installed ruby using rbenv Can any one tell me what I have messed up? Ubuntu 20.04 came with a shared library called, from the package libffi7. This library has been referenced by one of your ruby gems, ffi.
Webpacker is a wrapper around Webpack, but is not fully used in a default new Rails application. Let's see how to set up Rails with Webpacker, in order to use any kind of frontend assets. The minimal flag means "please install a default Rails app with the fewest possible dependencies".
A model can associate with other models by way of a polymorphic association. This can be useful when the associated models are not of the same class but share a common interface, or when a model shares the same type of relationship with multiple other models.
I was finally (just before submitting this) able to get bundle install to work by removing as a source and adding Why would gem be unable to access api.rubygems.
Ruby on Rails is a web framework that contains many libraries you’d need to create and deploy a successful web application. We often take for granted the ability to run rails new to create a fully functional web application with tons of built-in features.
This article was originally posted on my blog. Sometimes an array of data needs to be submitted in an HTML form. A form to send invites to a bunch of users for example. That'd just be a series of email fields; and in the controller; we'd want an array of the emails to iterate over and send invites.
Inspired by Django’s get() method, Rails now introduces #sole and #find_sole_by. The purpose of this query is given a set of constraints, to match only one unique record in the database.
Gone are the days when you have to use external gems to handle file uploads in Rails. These days Active Storage is built into Rails with support for multiple cloud-based storage services such as Amazon S3, Google Cloud Storage, and Microsoft Azure.
Gemfile is a well-known file even for not experienced Ruby developers.
Foundation 5.2 and Rails. How to set up a Rails application with Zurb Foundation. Zurb Foundation provides a standard grid for layout plus dozens of reusable components for page elements such as navigation, forms, and buttons.
Shipping is the real motivation for the deploy script mentioned in my previous post, “The Power of Scripting: A Deploy Script”. In particular, deploy is designed to lower as much as possible the friction associated with shipping.1
💎Rails tip💎 Are you dealing with an external API and not sure where to put that code? Using ActiveModel::Model module can be a clean way of doing so in a OO way. It's a model, but not connected to ActiveRecord/your DB. #ruby #rails #rubyonrails
The Rails helper excerpt can extract a chunk of text that matches a certain phrase, no matter where in the string it is. Simply filter down your records and then use excerpt on the email body.
I'm seeing a lot of disappointment about the speed of Ruby 3 out there. I think there are a lot of reasons for that, and I think they're worth looking at. So: why wasn't Ruby 3 faster? Did it break its promise? (Spoiler: I don't think so, but I understand why some people do.)
Paweł Urbanek Performance Consultant Tune Your Performance Blog Contact eBooks Migrate Heroku Postgres Database to AWS RDS - the Complete Guide Blog posts Feb 2, 2021 UUID Primary Key in Elixir Phoenix with PostgreSQL and Ecto UUID also known as GUID is an alternative primary key type for SQL da
Use the Rails highlight helper to wrap search result matches in tags. Pass the search term to your controller via params (e.g. params[:search]) and use that to filter down your results.
So, what exactly are WebSockets? Briefly, they’re a way to get around some of the restrictions of the HyperText Transfer Protocol (HTTP) used by default on the Web.
This is a special guest post from Kevin Gilpin of AppLand. Kevin reached out about an improvement to the Ruby on Rails Tutorial regarding an important type of database query optimization known as eager loading, which is the solution to a corresponding problem known as an “\( N+1 \) query”.
You may have implemented authentication in one of your apps, either directly with Rails’s has_secure_password or indirectly through a gem like Devise. Whichever way, you persisted user passwords in some way.
Michael Hartl here from the Rails Tutorial and Learn Enough. One of the topics covered by the Ruby on Rails Tutorial is sending email with Rails.
Heroku is easy to use and has a good marketplace. They make it really easy to deploy and to purchase additional resources. I like using Heroku but I want to also get a sense of what other Rails hosting services are like, especially ones with similar user-friendliness. Thanks in advance
MongoDB is a document database with the scalability, flexibility and the querying and indexing of the records. In this blog, we will cover how to install it in Ubuntu 16.04, configure and use it with Rails 6 application.
In this article, I will be discussing how to quickly setup a NoSQL database MongoDB with your brand new Rails 6 app. I am using Ubuntu 14.04, Ruby 2.5.1 and Rails 5.2 for this tutorial.
If you've been following me awhile, you know that I was hired by AppFolio years ago to measure Ruby 3's performance, especially on Rails. This has been a long trip. And that very first project is finally over: Ruby 3 exists and I can check its final, released Rails performance.
Rails 6.1 adds the ability to switch a role or shard for an application with multiple databases. This means it is possible to switch connections for one database instead of all databases globally. To use this feature, we need to set the below config in our application.
Simplified when we talk about the request that is coming to the Rails application, we usually consider two elements of the application: routes configuration and controller action. The route configuration decides which controller action should be triggered when the given request comes.
To run the default seeds.rb file, you run the command rake db:seed. If I create a file in the db directory called seeds_feature_x.rb, what would the rake command look like to run (only) that file?
Starting with Rails 6, Webpacker is the default JavaScript compiler. It means that all the JavaScript code will be handled by Webpacker instead of the old assets pipeline aka Sprockets. Webpacker is different from asset pipeline in terms of philosophy as well as implementation.
Rails version 1.0 is approaching its 15 year anniversary, and there’s reason to celebrate the framework's progress. There have been hundreds of amazing products built with Rails since its creation.
Why are we doing this? One of my favorite way to sharpen my skills with different frameworks is to build todo lists. It's easy and quick to build and building the same app in different stacks makes what is the same and what is different between frameworks very clear. In this tutorial, we will...
We’ve been living in the shadow of Ruby 2 for seven years now. Seven! Ruby 2 was released in 2013 (which incidentally is the same year as the initial public release of React 0.3.0!).
I'm creating a new rails application according to "Getting Started with Rails". The application starts normally in step 4.1. But when i create my first controller, i have a webpack error. I'm new in webpack, i have red all documentation, but i don't understand what is wrong or missing...
In order to install Ruby and Rails on Ubuntu 18.04, first I had to completely wipe my first, abortive attempt. That proved to be harder than expected. So, in order to save others the effort I had to go through, here’s what I did.
When developing applications we often have methods that run slowly. Perhaps they need to query the database, or hit an external service, both of which can cause them to slow down.
If you’ve ever used Ruby on Rails, you’ve probably come across the concept of concerns. Whenever you jumpstart a new Rails project, you get a directory app/controllers/concerns and app/models/concerns.
This blog is part of our Rails 6.1 series. If we want to omit some of the features then we needed to skip them like this.
Welcome to the first post in our series about Ruby on Rails Patterns and Anti-patterns. In each of the posts, we'll take a deep dive into all sorts of patterns you might come across while working with Rails apps.
A simple search form is great, but one with advanced search options can have many use cases. Can you imagine Amazon with a search form that only accepts item names? Pssh...that sounds like a nightmare to me. I prefer to provide more options for my users.
In January 2019, we set out to rewrite the critical software that powers all online storefronts on Shopify’s platform to offer the fastest online shopping experience possible, entirely from scratch and without downtime.
By Plataformatec. This README is also available in a friendly navigable format.
I was recently on Jason Swett’s podcast again. He’s a great interviewer and I always have fun with him. By Twitter request we talked about… When would you not use Rails? It’s a great question.
👋 Welcome! This post contains everything I learned and did that was not documented as part of my Ruby and Ruby on Rails 6 learning. I am new to the ecosystem and really looking forward to feedback, if you have any, drop me a comment here!
To apply a template, you need to provide the Rails generator with the location of the template you wish to apply using the -m option. This can either be a path to a file or a URL. You can use the app:template Rake task to apply templates to an existing Rails application.
Metaprogramming is an integral part of Ruby, more so than in any other language. Many frameworks and libraries rely on it, so if you want to know how those tools function, you will have to learn what goes on under the hood.
Ansible Rails is a playbook for easily deploying Ruby on Rails applications. It uses Vagrant to provision an environment where you can test your deploys. Ansistrano is used for finally deploying our app to staging and production environments.
If you're looking for Ruby on Rails Action Mailer configuration then you are in the right place. Gmail, Amazon SES, Mailgun, SendGrid, and Mailchimp's Mandrill are the most popular choices for sending emails with Ruby on Rails.
Since you're reading this post, chances are you've heard Rails 6 installs both Webpacker and Sprockets and you're wondering WTF is going on. By the way, it's a whole May of WTFs for Rails. Wait, don't Sprockets and Webpacker basically do the same thing?
This is the ultimate tutorial to Ruby on Rails application monitoring in 2020. So if you want to sleep through the night with your Ruby on Rails application monitoring in place, you are in the right place.
Imagine the following scenario: You have a database full of job titles and descriptions, and you’re trying to find the best match. Typically you’d start by using an ILIKE expression, but this requires the search phrase to be an exact match.
If you are looking for the cover to cover tutorial on Ruby on Rails Security Best Practices, you have come to the right place. So if you are looking to join the club of those who are better safe than sorry in their secure Ruby on Rails development, read on.
When I landed on this new job position at EBANX one of my very first tasks was to get the top 10 issues of a Ruby on Rails app used all over the World, with around 3.5 million requests every month, using data provided by a monitoring tool which I had never worked with (Datadog).
Rails 5.2 introduced Active Storage as a way of managing attaching and saving files to Active Record models. This guide will cover how to use Active Storage on Heroku.
My name is Nate Berkopec. I'm a Rails developer and a speed freak. Over the past 4 years, I've seen dozens of different Rails codebases. Many were for well-funded startups, from Ivy-League incubators like YCombinator or 500Startups.
Let’s say you want to create data with certain data types (bool, float, text, integers) with special characteristics (names, address, color, email, phone number, location) to test some Python libraries or specific implementation. But it takes time to find that specific kind of data.
This is the ultimate guide to Ruby on Rails project RuboCop setup in 2020. Let's get started.
This is the ultimate, step by step Ruby on Rails guide to RSpec testing framework configuration in Ruby on Rails project. Let's get started.
The credentials feature is a way of storing secrets that you don’t want to keep in plaintext, like AWS credentials for example. (In fact, the one and only thing I keep in my main Rails project’s credentials are my Active Storage AWS credentials.)
As we all know that first release candidate of Rails 6 is out with exciting features and refinements in existing features. Today we will look into one of those features, which is webpacker. It is now by default in Rails 6 as a Javascript Compiler.
This is the ultimate guide for your next Ruby on Rails project setup on Github with CircleCI for continuous integration in 2019. Let's get started.
UUID also known as GUID is an alternative primary key type for SQL databases. It offers some non-obvious advantages compared to standard integer-based keys. Rails 6 release fresh out of beta introduces a new feature in ActiveRecord that makes working with UUID primary keys more straightforward.
Starting a new project using Ruby on Rails is very easy. While with a lot of other frameworks you spend some time building a basic MVC-carcass, Rails does everything for you thanks to its built-in scaffolding feature.
Sign in Sign up Email Forgot password? Password Remember me
Svelte is slowly rising to fame these days and it’s getting more and more traction with new version 3 being released in April. If you’re interested in how to get started with Rails and Svelte, this is the right post for you! We’ll go through the whats, the whys, and the hows between the two.
At Shopify, we use Ruby on Rails for most of our projects. For both Rails and Ruby, there exists a healthy amount of stigma toward performance. You’ll often find examples of individuals (and entire companies) drifting away from Rails in favor of something better.
What they have in common is that, as they've grown and added more dependencies/gems, they take longer and longer to start. Development, Test, Production, console, it doesn't matter; some take 60+ seconds.
This is the first post in the More than "Hello World" in Docker series. The series will help you ready your app: from setting it up locally to deploying it as a production-grade workload in AWS. There is no shortage of web tutorials on how to display "Hello World" in Docker.
As most Ruby on Rails fans might be aware, Rails 6 is coming soon, and bringing a number of eagerly awaited features and changes.
Discover the lesser-known parts of the next major framework upgrade, appealing to mature applications that have been around for a while. Instead of focusing on “greatest hits,” we will walk you through B-sides and rarities that make new release enjoyable in subtler ways.
Your Rails application is the heart of your business. Built with great care, using best practices and being tested extensively. You trust your codebase and you are ready for release.
Active Admin is a Ruby Gem. More accurately, it’s a Rails Engine that can be injected into your existing Ruby on Rails application.
Since Ruby on Rails is not the fastest web framework out there you sometimes need to improve the performance in order to keep up. This post will list 42 of my favorite performance tips for making your app faster. Ruby and by extension Ruby on Rails is not known for its performance.
Rails rake tasks are commands that automate specific actions to be used either by the developers or by other mechanisms (e.g.: a deploy that will invoke rake tasks). Many tasks come configured with Rails out of the box to provide important functionality.
Originally I shared this digest to Syndicode blog. More than a month passed since I made the previous Rails digest issue. Well, but there is no particular need to create it more often, because even the most accurate selection needs time to separate the wheat from the chaff.
Polymorphic associations can be tricky to understand and many times one can get confused about when to use them, how to use them and how they are different from other associations. In this article we will go over these issues.
To give back to our community of developers, we looked at our database of thousands of projects and found the top 10 errors in Ruby on Rails projects. We’re going to show you what causes them and how to prevent them from happening. If you avoid these "gotchas," it'll make you a better developer.
ActsAsTree extends ActiveRecord to add simple support for organizing items into parent–children relationships. By default, ActsAsTree expects a foreign key column called parent_id.
This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a position column defined as an integer on the mapped database table.
Have you ever wondered what the secret_key_base value is and how it’s used in a Rails application? This configuration value was introduced in Rails 4 and is usually defined on a per-environment basis. It’s purpose is simple: to be the secret input for the application’s key_generator method.
Base or "skeleton" application for Ruby on Rails 5.1 projects. Built to minimize the time spent writing boilerplate code and performing repetitive setup tasks. It comes with a preselected set of tools which I believe to be the most efficient and widely used.
This is the second article in the “Authentication with Rails” series. We are going to discuss Devise, a popular, full-fledged authentication solution by Platformatec.
My favourite part of Rails is clearly ActiveRecord’s scopes. Their expressiveness and their reusability is simply great. You’ll see below 5 tricks I usually bring during consulting missions.
When I was thinking about creating something to showcase using ActionCable (websockets) in a Rails app with React, I first thought of building a chat. But everybody builds a chat. So next, I thought about a realtime dashboard.
An application template that creates starter applications for Rails. It’s the Rails generator on steroids.
Quite often I find myself spending hours debugging(and sometimes finally deleting) a flaky feature test. Finally I decided to stop doing that, and after watching the Rails Conf talk about system testing, decided it was time to act.
As you might know from previous posts, I keep a Rails playground project around. That’s a small application with a bunch of models, controllers and accompanying tests.
Adding new code to Rails controllers can bring a couple of problems with it. Sometimes controller actions get really big, and they tend to do a lot of things. Another common problem is an increase in data over time, which can lead to slow page loading time.