Kitchen to Coding


A blog to document my progress from chef to software engineer

Simplified Search Query in Rails

Context: My last couple of posts were about setting up a simple search in my Rails app, and I have since revisited that code and revised it to be more clean and efficient. For the search I use a plain old Ruby object (PORO) to create a deck search object, and then use those attributes to finds decks that have matching fields. These fields are :admin_approved, :level, and :user_id. Initially I filtered through one at a time rather than crafting a succinct search. Here is what the original deck search class looked like: ``` class DeckSearch attr_accessor :admin_approved, :level, :user_id


JS Filter in Rails App

Context: In my last blog post I created a search filter for my Rails application by creating a class and controller to handle querries, and then rendering to the page. In this blog, I’m going to explore doing this with JavaScript instead. It’s perhaps not as elegant, but it doesn’t require going back and forth through the MVC structure. So, let’s get straight into it:


Creating a Simple Search with Rails

Context: I’m working on a simple (at least for now) CRUD Rails application that is designed for teachers and administrators to create and edit sets of flash cards for students to use as study resources. Currently my table structure consists of Users, Decks, and Cards. A Card belongs_to a deck, and a Deck belongs_to a User. Also, the :users table has an :admin boolean, which of course denotes if that user has administrative capabilities, and the :decks table has an :admin_approved attribute, which means that it has been reviewed and deemed acceptable as adequate study material for students. What I’m implementing in this blog is a search tool that an administrator can use in order to edit decks that don’t belong to them, especially for being able to change a deck’s :admin_approved attribute to true.


Tweeking Vanilla-Nested for Rails

The project I’m working on requires a nested form where a Deck has many Cards, and I wanted the user to be able to add and/or remove as many cards as they want. I was doing some research on how to accomplish this, and it seemed like finding a gem was the best way to go. I tried Cocoon, but I couldn’t get it to work for some reason. I found a different gem: vanilla_nested, which seemed like to be more streamlined, so I gave it a shot instead. I ran into a little bug with it, but I was able to get into the code, tweak it, and then it worked great for me, so I’m going to go through how I got it to work.


Implementing OmniAuth

Ok, my last blog post was about setting up OmniAuth from Facebook, so this post will be about actually implementing it within the application.