Search Your Model Based on Category

For my Yelp-like project, I wanted to be able to search my model based on a category. I tried following the two Railscasts and browsed various solutions, but those didn’t work as I was trying to do something slightly different. My Category was its own model, so when I wanted to search my Vendors, I had to search the :category_id. I spent a week trying to figure out this seemingly easy task. I even had a question out on StackOverflow and was working with a mentor who couldn’t figure it out either. I was stumped until I went to the Rails Meetup and one of the mentors spent 5 minutes with me to give me the correct code.

I could have easily gone with one of the search gems (searchkick, sunspot, etc.), but it seemed like those were overkill. Maybe I’ll use one of those gems in the future, but for now, here’s my code to show how I did it manually. I’ll leave out the styling so you can see the straight Ruby.

vendor.rb (model I want to search)

def self.search(params)
  vendors = Vendor.where(category_id: params[:category].to_i)
  vendors = vendors.where("name ilike ? or email ilike ?", params[:search], params[:search]) if params[:search].present?
  vendors
end

vendors_controller.rb

def search
  @vendors = Vendor.search(params).order("created_at DESC")
end

layouts/_search_form.html.erb (rendered this in my other view)

<%= form_tag search_vendors_path, html: { class: "row-fluid" }, method: :get do |f| %>
  <%= text_field_tag :search, params[:search] %>
  <%= select_tag 'category', options_for_select(Category.all.map{|c| [c.name, c.id]}) %>
  <%= submit_tag 'Search' %>
<% end %>

List of Resources to Learn Ruby on Rails

With the popularity of Ruby on Rails, hundreds of bootcamps/courses/tutors/etc. have propped up as the best solution to helping you learn how to build a web application. I’ve been vigorously trying to find a great resource that doesn’t charge me an arm and a leg to learn. As I continue on my path of learning Rails, I am finding it more and more difficult to find a reliable source to teach me how to code. Again, I’m trying to keep my costs low. Maybe the old adage of “you get what you pay for” is very true. Sure, anyone can sign up at Codementor or throw money at gSchool. Money can buy you many things, and learning to code is one of them. But, like most folks, I don’t have extra money to buy myself an education. If I did, I’d get a degree from a reputable university in computer science. At least then I’d have something to show for it.

This is just my opinion, but I don’t believe the affordable resources provide enough value. It seems like they’re all just like you and me: they can scrap things together from the internet and put together a basic app. The Rails community is mostly a self taught one. It’s hard to find someone who actually knows what they’re doing versus one who Google’s their way to building an app (not saying that’s always a bad thing).

Done with my rant. Here is an updated list of resources I’ve used/attempted to learn Rails.

  • Hartl’s Rails Tutorial (Free)
    Great resource for the true beginner. Test heavy, which I don’t recommend doing if you’re a complete beginner like myself. He has a new version out that I haven’t tried, but I’d suggest steering clear of the testing sections.
  • Jumpstart Lab’s Blogger Tutorial (Free)
    Another great resource for a beginner. I actually think this should be the first tutorial you do as it builds a basic blogging app that uses simple relations. I went through this 4-5 times in the beginning just to really learn the syntax. Towards the end, I was able to complete this without having to reference the tutorial, which I highly recommend everyone do. I skipped the Merchant tutorial because it was filled with scaffolds.
  • Agile Web Development with Rails 4 ($45)
    Decent book. Relies on scaffolding. You build a basic ecommerce site with very little CSS. Not the prettiest thing in the world, but it teaches you some AJAX along the way and introduces an algorithm for counting items in your shopping cart. The second half of the book was a huge blur since it does a dive into Rails – ActiveRecord/ApplicationController/etc.. Hard to grasp if you’re new to it like myself. In all honesty, I followed the tutorial once and never went back to it. I wouldn’t recommend getting this book. If you do, get it used.
  • BaseRails ($49)
    At the time, this is how much I spent on it. They were very new, so I bought their Etsy tutorial. They’ve added a Yelp tutorial and a new payment structure. It could just be my ignorance, but it seems like the folks here are self taught. Looks like they were able to Google themselves into building a basic app. At the time of this post, they are now charging a monthly subscription for $25. They’re a little slower on getting up new tutorials. I’d sign up and go through both the tutorials as fast as I can.
  • Elance ($180)

    I found two different people on Elance to help me learn Rails. I have mixed feelings about finding folks on here. Again, I try keeping costs low, so the hourly rate was important when searching for a tutor.First person: I think working with someone physically provides a much better learning experience. I found a local developer at $30/hr. I only spent 2 hours with him because this was my first time and wanted to try it out. Very knowledgeable. He had a day job as a Rails developer and had some side gigs as well. Gave me some good advice and worked through an app I had. Introduced me to Rake tasks to generate my dummy data (versus manually entering everything in). He’s a bit out of my price range, but would definitely come back to him for a code review once my Yelp-like app is complete.

    Second person: $20/hr, located in Asia. It was actually great because he was American who moved to Asia, so communication wasn’t a problem. He went to school and seems like he really knew programming. His Rails was all self taught, so a lot of his knowledge was what he found on Stackoverflow/Google. Seems like he could find a solution and hack it to make him do what he wants. Wasn’t a bad gig. He taught me some useful things. Would probably use my first person before using him again.

  • Meetup (free)
    I highly suggest you go to your local Meetups. The one here in Minneapolis is free, but I know some charge a small fee to join. We have a monthly meeting that I try to make, depending on where I’m at for my project. If I’m stuck and have something to ask, I’ll go. The only thing is, there are only a handful of mentors for a group of ~30 people. I really only get one chance to ask one question before I feel like I’m hogging them. Will definitely have someone here do a code review of my app once I’m finished. An added bonus: it gets you involved in the community. The Ruby/Rails community is very tight knit. If you want a job as a developer, might not be so bad getting to know some folks here.
  • Fiverr ($5)
    My experience with Fiverr has been negative. Most people try to do the bait-n-switch. They post a gig up for $5 and when you contact them, they tell you it’ll be 10 gigs to do what you want. I wouldn’t recommend using Fiverr. Again, you get what you pay for. I did get some useful tips from the one gig I bought, which was probably worth the $5, but nothing more.
  • RailsMentors.org (free)
    Another decent resource. It’s hard to find a good mentor though. I try finding one in my timezone and was lucky enough to find someone willing to help. A few others I tried reaching out to never responded and the ones that did said to contact them only if I run into an issue. I was able to find a diamond in the rough, but the caveat is they’re doing this for free. So I have to respectful of their time and if they’re busy, I may wait 1-2 weeks before getting a response.
  • CodeJinn ($20/session. Did not spend money)
    I was disappointed with CodeJinn. Their advertising came off a little misleading. I was going back and forth with the founder on what it is they actually do. When they introduced one free session for new members, I signed up. I was under the impression that they would walk you through your app, with little checkpoints to count as one of their “sessions.” That was not the case. They are basically there to help you get through a bug you’re facing or help give some insight on what you can do for different issues (may not necessarily be helping you code, just telling you where to go for the code). My one conversation lasted 5 minutes.
  • RailsHotline (free)
    I have not tried this yet. Seems like they are going through some technical difficulties (or maybe just lack of traction). Have not found someone online ready to take a call and no update on their Twitter. Hoping they get back online so I can try them out. Looks promising, but I have a hunch they’re like the others I’ve tried.
  • Railscasts (free. Optional subscription)
    Great resource and one that is most recommended. Only downside is that Ryan Bates has stopped producing new screencasts. I still come here for the various things I’m looking to do.
  • GoRails (free. Optional subscription)
    Chris Oliver recently started this screencast series. Looks like he’s trying to pick up where Railscasts left off. I haven’t gone through many of his videos yet only because he’s covering the very basics right now. I’m hopeful this will become a solid resource comparable to Railscasts.

There are many others I’ve tried but without much success, so I didn’t mention them here (Codecademy, Zombies, Appcasts, etc.). Those are all good, but I learn best by building a real-world application. That’s why I favor tutorials over small snippets. Let me know your thoughts if you’ve tried any of these. A lot of the cheaper resources barely scratch the surface of building a viable application. Maybe it’s time I spend huge bucks on Codementor? Who knows. I probably won’t be doing that. I’m going to try a few other things before throwing in the towel and spend my life savings on a proper Rails education.

The Importance of Taking Breaks while Coding

Overcoming a complicated bug or seeing your app finally come together constitutes a well deserved celebration. Now, you don’t have break out the wine and throw a lavish party, but I strongly believe indulging in these small little accomplishments is a healthy practice. When you’ve spent a hundred hours to fix a bug and get the application to function as expected, I encourage taking a small break.

For example, this past weekend I was putting together the styling for my app. I don’t have a creative bone in my body, so I found a theme and started incorporating it. Up to this point, I’ve been neglecting my styling as my main goal is to learn Ruby. I’ve been relying on Bootstrap just as a tool to help make my app a little more bearable. So as I started putting on the CSS files and using the different classes in my views, it was rewarding. I was able to do most of what I wanted to do from a backend perspective, so the fun part of seeing the frontend was exciting. The different layouts and buttons brought my vision to life and was even more encouragement to keep on going.

So what did I do when the main pages and functionality was built? I took a break. After hours of putting everything together and neglecting my family, I closed my Mac and used my free time playing video games, with family, and not thinking about code. Most developers will agree that when you come across a particular bug or add an enhancement, you’re truly not contempt until it’s finished. You’ll spend hours/days/weeks on these tasks, only to have another one right at your door.

I know it’s hard to stop when you’re on a roll, but separate your tasks into small sections. When you complete one, take a break, because I guarantee you that more frustration and long, isolated hours will come.

My Weeklong Issue Fixed in 5 Minutes

Anyone who is self-teaching Rails understands that there are definitely major pain points that can’t be relieved by Google searches or StackOverflow questions. As great a resource as those two are, they simply don’t dive any deeper than junior-level knowledge (in my opinion). Most of the questions on SO are from new learners and most of the blog posts only scratch the surface of the topic they’re covering. The Ruby community is known to be a self-taught one, learning from each other. You won’t find low level classes at any of the colleges or other academic institutions, at least nothing that covers Ruby as intensely as C++ or Java.

All that being said, I thought I had a simple task. All I wanted to do was search multiple columns in one model, by an associated category. I spent a week asking a question on SO and doing all sorts of Google searches. I went through all the gems (Ransack, Searchkick, and Sunspot/Solr). I even tried learning a little more about Elasticsearch, but decided against it because it’s almost another language completely in its own right. For whatever reason, I couldn’t find the solution. Or, if one was presented, it didn’t work.

I spent nearly a week trying to do what was seemingly an easy task. I just wanted to search my model that’s in a specific category! I spent most of my free time, time that I could have spent with family, in frustration. Thankfully, the weekly Rails Meetup was around the corner. Lead by a few savvy Rails folk, I was able to get one of their attention and explained my conundrum. After 5 minutes tinkering around with the syntax, my problem was solved. I was excruciatingly close, but just had to rearrange a few lines of code and add some extra syntax. My week’s long problem just needed a pair of seasoned eyes to take a look at and figure out.

The path of a self-taught developer is a frustrating one. On to the next issue!

My First Stack Overflow Question

After days of trying to figure out how to create a search form that searches a model by category, I finally built the courage to post my issue on Stack Overflow (SO). There are plenty of resources of building “simple search forms” or even “advanced search forms”, with RailsCasts being the number one hit. But, my dilemma is that my root path wasn’t to the model itself. It’s actually pointing to a different controller (in my case, pages#home).

So I played around with all the different tutorials and tried many different solutions. In retrospect, I was actually very close. I was under the assumption that because I’ll be on my “Pages” controller that I needed to put some sort of search syntax there. Instead, I needed to create the search method on my model’s controller and then call it from wherever I wanted (for me, it was pages/home.html.erb).

I won’t get into the details, but it’s amazing that I can ask a question to the general public and someone answers within a few hours. I literally posted my question on SO before going to bed and when I woke up, someone had already answered within 5 hours of my post (thanks @Val!). Now I know firsthand how awesome SO is and why it’s the go-to place for programming questions. I’m just wondering who in the world watches for new questions and answers them in their spare time? I’m guessing SO has some sort of notification for tags that sends out questions to those who subscribe. If not, they should. Maybe someone will create a SO clone, specific for Rails ;)

I digress. In a nutshell, it’s amazing how useful SO is. My only hope is that someday I’ll be able to return the favor when I know enough. Until then, I’ll keep on moving forward with my Yelp clone project and update you all on progress.

Best Way to Learn Ruby on Rails? Are Bootcamps Worth It?

I’ve tried almost all the free resources out there to learn Ruby on Rails and even some paid ones as well. In my honest opinion, free or paid, the quality has been the same. I’ve been greatly disappointed in the various paid resources I’ve tried (won’t name them here). Granted, it’s never been more than $50 per resource, but it leaves me weary as to whether or not I should spend more. We have a local class here made by developers in the area, charging a “discounted” rate of $650 (original $1,500) for 6 sessions of learning RoR. I was contemplating whether or not I should take it, but after speaking to someone who did, they suggested I put my money elsewhere. That’s why I haven’t pulled the trigger yet on Tea Leaf Academy or Bloc. The only promising paid resource I’ve found is Pragmatic Studio’s Rails courses. Even then, I haven’t found many recent reviews aside from what they post on their site. You’d think that if people are willing to spend $600+ on other resources that one costing $179 would have more reviews.

Bootcamps are popping up all over the country and the world. There are hundreds of them promising to make you a decent developer within 3-6 months. I’ve been doing a lot of research as to the effectiveness of these programs and it seems like the pedestal they were once on is crushing beneath their feet. Initially, I think companies were hiring these alum because it was a fresh, new approach to learning a technical skill. But, at least from what I’ve read, they’re now discovering that folks who come out of these bootcamps aren’t nearly skilled enough even for a junior developer role. I met a local person at a Meetup who graduated from DevBootcamp and they were still looking for a job after 2-3 months since being out of the program. Similar stories are cropping up all over the place, and I’m hoping more do. There is a misconception that spending $10,000+ for 3 months of work in a completely new field with one of the steepest learning curves will land you a job. Granted, bootcamps don’t guarantee you a job afterwards, but that’s often the hope. Why do you pay thousands of dollars to go to college? So you can get a decent job afterwards. Why do you pay to go to a developer bootcamp? Same answer: to get a job. If someone wanted to learn to code for fun, they buy a book or join the local Meetup.

My suggestion is this: learn as much Ruby on Rails on your own with the free/cheap resources. Don’t pay more than a few hundred dollars, TOTAL. If you must insist on spending thousands of dollars, find yourself a professional, senior level developer that’s local. I guarantee you that if you offered a senior level developer $10,000 to help you learn RoR, they would take you up on it. What you learn from a one-on-one, in-person lesson are a hundred times more valuable than a class setting with a generic approach. Not only that, but you gain a reference that you can use for your job applications.

I’m taking a slightly different approach now. I’m done with the this-tutorial-fits-all learning. I won’t say here, but I’ll give an update once I’ve had the time to assess whether or not this new approach works, or at the very least, give my experience.

Current Project

I’ve decided to transition to a different project from my Tuition Reimbursement app. Initially, I thought I’d stick close to what I know: building solutions for HR related issues. However, from experience, that isn’t an industry I’d like to stay in, at least from a software perspective. Millions of companies handle the same issue millions of different ways, which is why I think folks like Oracle and SAP can charge as much as they do for their software. Trying to accommodate the countless practices and integrating all the different pieces of software is a huge headache. That being said, I think I’d like to make a pivot and build an app that’s geared more towards the general public versus a company.

So, my new project is a Yelp clone. My hope is that by creating various popular websites that I will gain enough knowledge to build my own app. I have no idea what that is yet, but I think it’d be a good start if I knew how to build Facebook, Yelp, Amazon, etc.

We’ll see where it takes me.

Hitting a Road Block

I’ve been a bit busy these past few weeks but will now have more time to focus on my learning. Where I last left off, I hit a road block. Not necessarily about finding a solution to a particular problem, more from an overall perspective. It seems like the various tutorials and resources online will only get you so far. You’ll be able to create simple models with simple relations, but as far as building a more robust app, they just won’t suffice. When I hit a snag, I browse through StackOverflow and ask a question. If I receive a solution, it doesn’t take long for me to run into another snag. It seems that when you start getting deeper into what you want to do, the learning curve spikes. Most of the online resources will only get you so far. Even going through the deep dive Rails books will seem convoluted because there’s really no context.

I think I’m at a point now where I need to find a mentor. I can get myself to a simple app, but if I want to start building the intricacies, I’m thinking a mentor would help push the rate of learning much faster. Right now, I’m stuck at ask-specific-question-online-wait-for-answer curve. That being said, I’ve hit a bit of a plateau. I can’t move any further on any task without the help a higher level developer.

My goal for the next coming weeks: finding a mentor. That’s actually a lot hard than said. How does the mentor benefit from a mentee? A mentor will more than likely be working on their own projects or having a day job. Their time is valuable, so why would they bother helping someone without any sort of return? The RoR community has a great reputation of helping newbies learn, but outside of the local Meetups, I haven’t been successful at securing a dedicated mentor. So, I will continue my current process of learning, but at the same time searching for someone who would be willing to sit down with me for a couple hours here and there to go through either my project or theirs.

Lynda’s Ruby on Rails 4 Essential Training

Life’s been busy, but I think it’d be good to squeeze a little review in here.

Lynda.com has a plethora of tutorials, from development to design to photography. They’ve really established themselves as a go-to place for beginners who want to learn just about anything. With the amount of Rails tutorials out there, I’m a little surprised that I couldn’t find too many reviews. At the cost of $25/mo, I figured it’d be a small price to pay to get a look into the course.

Kevin Skoglund walks you through creating a very basic CMS. He starts from the grass roots, going over what Ruby/Rails is and discussing what classes, modules, etc. are. If you’ve never touched RoR before, this is a fantastic place to start. He’ll go through all the basic details of RoR: navigating the terminal, playing with irb, getting into the rails console.

Although his explanations of what he’s doing are well thought out, his approach is a little convoluted. I skipped nearly the first half of his videos since I’ve already been learning on my own for a few months now. However, I completely get lost when trying to follow his course. He mixes his example code with the actual project you’re working on. So you have to watch the videos in their entirety or else you’ll lose track of where you’re at. I’m not a fan of this method as it forces the viewers to watch every minute of the videos instead of being able to use it as a reference.

Another dislike I have is that he uses old methods (maybe because it’s an older tutorial) that are no longer relevant. Or, he’ll start coding something knowing that we’re going to change it later. While I get that this (might) help with understanding Rails, it became very frustrating. Why are you telling me that we’re going to do something now knowing that we’re going to have to change it later? To me, it makes more sense if we do it right the first time instead of confusing everyone with the this-is-what-we-did-before-but-now-we-do-it-a-new-way.

For the money ($25/mo), this is a great hand-holding tutorial for absolute beginners. But, if you’ve been playing around with Rails for some time now, or have even gone through a few tutorials already, I’m not sure it’d be worth. I like being able to reference material, and the way this tutorial is structured, it makes it nearly impossible to find what you’re looking for. Granted, I didn’t pay to get the source files, but you shouldn’t have to. This was definitely a good project to go through as it exposes you to back-end development, but the approach is confusing and  you can lose where you’re at.

My final review: at $25/mo, go through it as fast as you can if you’re a complete beginner. But if you’ve gone through the various tutorials (Hartl, JumpstartLab, RailsGuides), I’d skip this series and invest in a book or a different subscription.

Login Page

I’ve been trying to work on a login page for my app for a couple weeks and got my answer at the local Rails MeetUp (a place I highly recommend you go to for your area). Essentially, I wanted just a one page login form that escapes the application.html.erb. So I didn’t want it to include the header/footer/etc. of the general app. Once a user logs in, they’ll then be taken to the app.

Here’s the solution I received (using Devise for authentication and user management):

  • Rails looks through the views first to find a file that matches the controller before looking through the Views folders
  • That being said, I needed to create a folder under the Devise folders called “Session” (Devise has a SessionsController that isn’t created)
  • In that folder, I created a file called “sessions.html.erb”. This is where I put my form and any styling.

You can find the solution on my Github. I’ll update this post later to include a visual of my file layout too.