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 […]

Caching the API response in Rails

April 23rd, 2015


I’ve been looking at different methods of implementing low-level caching for the responses to my API requests. Kevin at Tealeaf recommended Faraday HTTP Cache to me. It looks great and I want to try it out, but I was hoping to see if I could get my current setup with HTTParty and Dalli working. Here […]