Dom's Dev Guides

A collection of notes and instructions about web development, debugging, and task completion. Primary topics include Ruby on Rails and Javascript.

Tuesday, July 30, 2019

guide
Strings can be split using three built-in functions: Split() is a method that splits a String object into an array Reverse() is a method that reverses the array Join() is a method that joins an array into a string function reverseString(str) { return str.split("").reverse().join(""); } reverseString("hello"); more

Tuesday, February 19, 2019

guide
Assuming that you have Rails and PostgreSQL already installed on your workstation, follow the steps for a new or existing Ruby on Rails app according to your needs. more

Wednesday, January 16, 2019

guide
The ability to like or favorite posts is very common on websites. This guide will show you how to add this functionality to your Rails 5 application without adding unnecessary bloat from gems. This guide assumes that you have already implemented posts (or similar) and users to your application and will not cover these steps. Let's go over some design considerations before we begin. While everyone can view a post, only authenticated users can like posts by clicking a link or icon.  We're keeping it positive by just tracking likes.more

Monday, May 21, 2018

guide
For use with trusted/cleaned data. Add to application.rb def truncate_and_link(text,options ={}) length = options[:length] return text if length.blank? url = options[:url] || '#' output = raw text.truncate_words(length) output += link_to('more', url) if text.size > length output.html_safe end Adapted from: http://itiansrock.blogspot.com/2013/01/truncate-and-link-text-helper-in-rails.htmlmore

Friday, May 18, 2018

guide
Problem: Ransack will only search for one keyword or phrase such as, "Jumpity Jump", without quotations. Using quotations or commas such as in "Jumpity Jump" or, "Jumpity, Jump" (with or without quotations). returns a blank result. Test conditions: Randomly selected records were edited to include varied words/phrases in searched fields, such as in the following examples: jump jumpity jump jimpity jump jump rabbit jumpity jumpity rabbit Solution: Custom predicates added to initializer based on Stack Overflow answer linked at end.more

Monday, May 07, 2018

guide
Font Awesome 5 SVG icons use javascript to find <i> tags with an icon class and replaces them with an <svg> tag. Turbolinks online displays these icons on initial page load and/or refresh, however when following a link, Turbolinks reloads the page and not the icons. This guide assumes that you have already loaded font awesome into your project using your preferred method. For what its worth, this guide uses the font awesome CDN more

Tuesday, May 01, 2018

guide
A box plox, or box and whisker plot, is a way to visualize the spread and centers of a data set. The measures of spread include the interquartile range and the mean of the data set. The measures of center include the mean or average and median. The lines extending from the boxes are known as the "whiskers", and indicate variability outside the upper and lower quartiles.  Outliers are plotted as individual dots in-line with the whiskers.  Box plots can be drawn vertically or horizontally.more

Thursday, April 26, 2018

guide
Add style options when initializing the Stripe Element object, like so: var style = { base: { // Add your base input styles here. For example: fontSize: '16px', lineHeight: '24px', iconColor: '#c4f0ff', color: '#fff', fontSmoothing: 'antialiased', fontWeight: 500, '::placeholder': { color: '#ffffff', }, ':-webkit-autofill': { color: '#ffffff', } }, invalid: { iconColor: '#FFC7EE', color: '#FFC7EE', }, }; View all Element options more