Steven Brooks' Blog

Student @Flatiron School

Serialize Attributes

So after I successfully jail-rigged my blog, I can now make new posts. I have a bunch that I want to talk about, but one I wanted touch on today was serializing attributes for a model.

Here is the scenario. One of the index pages for my currently client lists all the items they have available for rent (it’s a music company). They have microphones, computers, instruments, anything you could rent. It’s probably about 10 different categories of products that a customer can rent.

I built the back end with ActiveAdmin so the client can easily change the content of the site. The previous developer had hard coded all of the content, and the client was not comfortable going into the actual code to make changes.

So we have a rental page that lists all the items for rent. Because there are 10 different categories of items, do I want to make 10 different models and do the proper associations, or because the items only have names do I want to come up with something else?

I found out that I could serialize an attribute in rails. Its super simple:

My params

What we are doing his is simple, rather than creating a whole nothing model and creating the association, this model (staff), can have many titles, but those titles cannot have many attributes.

This was a really good way for allow the client to add many single attribute attributes to a model.

Test

If this works I have figured out how to jail rig posts.

I’m Back

Dear Everyone Who Has Read My Blog,

According to my watch, it should have been about two months since I last blogged. These past two months have been a very challenging time for me as my father recently passed away.

I will be starting up my blog again soon as within the last week or so I have been able to get back to programming. One of the things I have been working on has been speeding up my Workout App and adding Eager Loading into my application. Thus far I have eliminated a little over 60% of my queries.

Actually it’s probably better I do some stuff now. In my Workout App the individual workouts #show page has a visual representation of a users workout through the Google Charts. Originally, my #show action looked like this:

My params

Very strait forward, I had created a :graph method that would all the charts to work. When I do this, here is what the queries look like:

My params

Yuck, that’s 18 queries, and although it’s not very slow on my current app, if this workout had more than a few exercises with a few sets, it could be much slower.

Then I started looking into Eager Loading, which allowed me to turn my #show action into:

My params

Here, I am loading the routine for the action, that routine belongs to a user and has many lifts. Those lifts belong to an exercise and have many infos. So now when I Eager Load into the instance of routine and run the :graph method, we get this:

My params

Just 5 queries.

A Lot to Come Ahead

Everyone,

Unfortunately that last few days I have not been able to update my blog due to a family emergency. The good news is that I have still been finding a few hours here and there to get some coding work in. In the past few days I have authenticated users with Devise and Omiauth (together) as well as added the Letsrate gem to my workout application (allowing each exercise to have a 5 star rating). I plan on writing at least 2 post from these topics when I get a chance. I also spun up an app with the ActiveAdmin gem but I will only be giving a link to the pseudo (a little outdated) blog I followed for it. I will also be added a post for some of the gotcha’s I encountered while setting up Rspec and FactoryGirl today.

Push It Real Good

Real quick post today on deployment.

The apps I made thus far have all been deployed following these guidelines:

Spike Grobstein = Beast

If you were able to successfully deploy your rails app to production via Capistrano you have done all the heavy lifting already. If you make new changes that you would like to push to the server all you have to do is thanks for my boy Chris Gonzales:

  1. Go into your public folder on your local machine and write the command:

cap deploy:setup

  1. Follow it up by the command:

cap deploy

Ransack

Yesterday I worked on another search gem this time being Ransack. In Outlinked we used Sunspot (who I’m not even going to give a link to) which I will never use again. I was very pleased with how Ransack went and how easy it was to use as well as have dynamic searching.

Ransack was very strait forward. This is what my html.erb file looked like. This allowed a user to continue to drill down their search (dynamic):

My params

Then you go into the controller and set your instance variable to the results of the search:

My params

And bam, you get a nice dynamic search (I’m wondering if these drop downs can be autompletes, that would probable make the UX a little better):

My params

Rails DataTables

As my last post stated, I was planning on doing some work on searches in rails. I have done two of them so far today with the first being Data Tables and the second being Ransack.

Datatables is pretty cool. It’s not necessarily just search but it looks like a really cool admin feature. You can search any of the column, sort any of the columns, and have pagination really easily.

You are out by adding the gem then once you do that you simply give the table you are trying to sort an ID.

My params

Then go into the corresponding JS file and add a little snippet:

My params

And magically this shows up:

My params

Searching Today

I’m going to try to start something new on my blog. Unfortunately the last few weeks I haven’t been able to code as much as I would have liked to (most of my time has been spent networking, interviewing, etc). So now I’d like do a few hours a day of different rails features and log what went on here on my blog. Today I’m going to work on search which will include manual search as well as some of the gems such as Sunspot. Ttyl.

It’s Been a While

Dear Everyone,

I’m sorry. It’s been a while since I last blogged. I graduated The Flatiron School a few weeks ago and am currently running all over the joint trying to find a great job with an awesome company. Rather than blogging, my days have been spend networking, interviewing, and running around like a mad man.

In the next few days I would like to highlight some of the things I have been working on (I have been trying out a lot of ruby gems).

Till then, have a good one, Steven

Learned a Little About Notation Today

So today I learned something drastically new. One of my classmates, who just happens to be a beast at programming, went to an interview yesterday for a very prominent company here in New York. They asked him a lot of CS questions because this was not for a junior position, and lucky, besides the fact that my friend is just really smart, he had a background in CS. So he smoked some of these questions.

One of the things he thought I should have a grasp on was O Notation. Now what I am about to say is me trying to replay the 20 minutes conversation I had with my classmate this morning.

O(1) describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.

O(N) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set.

O(N2) represents an algorithm whose performance is directly proportional to the square of the size of the input data set.

O(2N) denotes an algorithm whose growth will double with each additional element in the input data set.