Welcome to the Archives

April 23rd, 2017

Although I’m no longer maintaining this blog, I plan to leave it up for the foreseeable future in case the code snippets and tutorials are of use to anyone. If I have time to write more tutorials they will be in a separate blog which will be listed on my home page. Happy Coding!

What I Learned From Coding In A Team

September 3rd, 2016

Four months ago I went to my first Civic Hacknight meetup held by Code for DC. I didn’t know how much I would be able to contribute, but as it turns out they are used to having new people show up and start hacking. Even though I had never coded in a team before, they […]

Checkboxes in Bootstrap Forms for Rails When Using a Mongo Array

August 21st, 2016

There are tons of code snippets online for dealing with checkboxes in Rails with a SQL-type database, but during my frantic search the other day I couldn’t find much on displaying the elements of an array field in Mongo. This snippet uses gem Rails Bootstrap Forms (gem ‘bootstrap_form’). Thanks to my heroic team lead Colin […]

Testing an Uploaded Image With RSpec

July 17th, 2016

I had some initial difficulty testing my photos controller with an uploaded file for the :image field, because the test was reading :image as nil. What worked was wrapping the image in a content wrapper using Class: Rack::Test::UploadedFile. I have this implemented in my factory: image { Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, ‘/spec/support/my_image.jpg’)), ‘image/jpeg’) } The image file “my_image.jpg” […]

Customizing Strong Parameters

July 10th, 2016

I’m working on a Rails app to allow users to post information on places they want to go to and then add the places to their personal bucket lists. While the strong parameters for the create and update actions can commonly be shared, I wanted to set different permitted parameters for the create and update […]

Basic SQL queries

May 24th, 2015

Create a database: CREATE DATABASE places; Create a table with columns specifying the datatype: CREATE TABLE cities ( id int, city varchar(30), state varchar(2), costindex decimal(5,2) ) Insert a new row of data: INSERT INTO cities(id, city, state, costindex) VALUES(1, 'Reno', 'NV', 80.20) Insert data with empty columns: INSERT INTO cities(id, city, state) VALUES(2, 'Provo', […]

Singular Resources, Plural Controllers in Rails

May 21st, 2015

A common example of a singular resource is a user dashboard. A singular resource allows you to create a route to a single item without an id. Since you’ll typically have only one user dashboard you wouldn’t want to have to specify the id of the dashboard you want to access. resource :dashboard, only: [:show] […]

Link to image to update attribute in Rails

May 10th, 2015

In Rails, an image link can be created that will allow users to update an attribute. In the following code, users can click on an image to mark a particular screencast as watched. When the screencast is marked as watched, a different icon is shown that can be used to mark the screencast as not […]

Adding Images to WordPress Previous Post and Next Post Links

May 3rd, 2015

Adding images to the previous post and next post links in WordPress can enhance the look of your website. To add image links for a single blog post, just use previous_post_link and next_post_link and add any images and text you want to use as arguments: single.php <div class="prev-posts"><?php previous_post_link('%link','<p><img src="' . get_bloginfo( 'stylesheet_directory' ) . […]

My Rails New App Cheat Sheet

May 1st, 2015

I made this personal cheat sheet to remind myself what to do when I start a new rails app. 1.To make a new rails app specifying the version: rails _4.1.7_ new myapp This creates a new Rails app with Rails version 4.1.7 with SQLite3 as the default database. 2. Modify the Gemfile. This is my […]