Rails’ modest JavaScript framework is a great addition to its ecosystem

Stimulus, as indicated on the website https://stimulusjs.org/, is a modest JavaScript framework that is simple to understand and use, but it still brings powerful abstractions to enable advanced use.

In this tutorial, we’ll dive into some practical examples of how to use Stimulus. If you want to follow along, you can start from this tutorial’s repository base branch: https://github.com/rodloboz/stimulus-rails/tree/base

Installing Stimulus

We’re using Rails 6 which ships with Webpack by default. In the terminal, let’s import Stimulus into our project with yarn add stimulus (or npm). Then we’ll add the default Stimulus boilerplate in app/javascript/vendor/stimulus.js and require this file in index.js …


Rails’ modest JavaScript framework is a great addition to its ecosystem

Photo by Marius Masalar on Unsplash

You can see the finished code here: https://github.com/rodloboz/stimulus-rails or visit the Heroku app here: https://stimulus-rails-tutorial.herokuapp.com/

Stimulus, as indicated on the website https://stimulusjs.org/, is a modest JavaScript framework that is simple to understand and use, but it still brings powerful abstractions to enable advanced use.

In this tutorial, we’ll dive into some practical examples of how to use Stimulus. If you want to follow along, you can start from this tutorial’s repository base branch: https://github.com/rodloboz/stimulus-rails/tree/base

Installing Stimulus

We’re using Rails 6 which ships with Webpack by default. In the terminal, let’s import…


A quick overview of ActiveRecord polymorphic associations.

Photo by Cécile Brasseur on Unsplash

When developing our applications, we often encounter situations where two or more different models have associations that seem to be identical. For instance, we may have a Product and a Service model that have many photos, or a Project, a Contractor, and a Task model that have many comments. One way to approach this problem would be to use one child database table for each parent model:

class Product < ApplicationRecord
has_many :photos, class_name: 'ProductPhotos'
end
class Service < ApplicationRecord
has_many :photos, class_name: 'ServicePhotos'
end
class Project < ApplicationRecord
has_many :comments, class_name: 'ProjectComments'…


How to quickly set up two different types of users with Rails and Devise.

Photo by Katka Pavlickova on Unsplash

Sometimes we need to have different types of Users in our app. Of course, we could generate two different Devise models and have distinct signup and login flows, but there’s more than one way of achieving a similar result. In this tutorial, we’ll explore Rails’ Single Table Inheritance (STI) on a User devise model.

Let’s say that we have an app where the User model has the email, password, and other Devise related attributes, plus a first_name and last_name. Now, let’s imagine that there is one…


In this multi-part tutorial, we will be building a Ruby on Rails app that implements the look and the features of popular social media giant Instagram. We’ll use Rails 6, Webpacker 4, Turbolinks, Stimulus Js and Tailwindcss.

DISCLAIMER: While the purpose of this tutorial is to share knowledge and show how to implement certain features for learning, due to its length and text format, it’s not aimed at the novice Rails developer and it’s not an introduction to Rails. If you’re still unfamiliar with the structure of a Rails application, I recommend starting with some basic Rails tutorials first.

I’ve…


Aggregate points on a map in clusters with Ruby on Rails and Mapbox

When we have a geocoded model in Rails, we may want to display the records in our database as markers on a map. However, once you begin to have too many records close to each other, it ruins the map experience for your users.

One solution to this problem is to aggregate markers that are close to each other in clusters which break apart as soon as the zooms in. Mapbox’s mapbox-gl API has this functionality and we’ll implement it within the context of Rails.

We’re going…


Ruby and JavaScript are about to go head to head. Both of these scripting languages are dynamically typed and support object-oriented programming. We’ll examine their differences or similarities across some of their more common features.

Disclaimer: We’re only looking at modern JavaScript ES6 syntax here.

Photo by Pramote Polyamate on 500px

String interpolation

In computer programming, string interpolation is the process of injecting the value of a variable or an expression in a string literal.

In Ruby, this is called, you guessed it, string interpolation.

Ruby:

first_name = "Martin"
last_name = "Riggs"
puts "Hi, I'm #{first_name} #{last_name}."

In Javascript, the same thing can be achieved with template literals.


In this article, I examine the rails routing system, including its basic syntax, standard CRUD routes, nested resources, member and collection routes, namespaced and scoped routes, and other advanced patterns.

Photo by Steve Harvey on Unsplash

I often see beginners not taking full advantage of the powerful routing engine provided by Ruby on Rails. Often they’re using more cumbersome syntax duplicating code or, worse, breaking Rails conventions left and right. But before we dive into concrete examples, it’s important to understand what the Rails routes actually are. According to Obie Fernandez in The Rails 5 Way:

The routing system in Rails is the system that examines…


Learning how to code nearly two years ago turned my life around and changed my career. Whether you’re thinking of joining a coding bootcamp, currently attending one or have recently graduated, here’s my advice for before, during and after.

Photo by Christopher Gower on Unsplash

Last Friday, we wrapped up Batch 205 of Le Wagon’s coding bootcamp here in Lisbon. That’s 205 courses run worldwide for Le Wagon and the 9th batch in Lisbon. That got me thinking about how much I’ve come along since graduating from batch 49, the second batch in Lisbon, nearly two years ago.

With an estimated information technologies jobs gap of…


Subjects covered in this article: Ruby on Rails custom validation rules, each validator, displaying a date-picker with flatpickr and writing a model instance method to list all unavailable dates to be passed into the date-picker.

For the past 2 years, I have been teaching web development to several batches of the Le Wagon coding bootcamp. We teach a full-stack curriculum and during the final two weeks the students work in teams to ship two different Rails apps to production, one of which is a two-sided marketplace concept, where there are users who put up something for rent or for sale

Rui Freitas

Lead Teacher @ Le Wagon | Web Developer @ Light the Fuse and Run: http://lightthefuse.run/ | Photographer @ Rod Loboz: https://blog.rodloboz.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store