Hank Holiday

Your Learning Story

How I learned Rails - Part 3 - Doing research and picking gems

  • April 4, 2014 at 1:10 PM
  • Last updated over 9 years ago
  • Visible to public
I had no clue about this part.  I knew that I needed to figure out what the app was going to be shaped like, answering questions such as: 
  • What parts would be gems? / What parts would I code myself?  
  • What database would I use? / How would the database be structured?  
  • Where should I start coding?
What I didn't know was how to answer any of those questions with google.  So I phoned a very helpful friend who was also new to Rails, but was much farther down the path than I.  He had just launched a Rails-based project of his own.

Notes from call with friend

Source Control
Github for source control (worked with svn a while ago but git is even easier)

Bootstrap
The nice thing about bootstrap is
  • If you use it default, out of the box the html and css is super high quality.
  • It has a grid based layout system that’s easy
  • It’s almost automatically responsive
  • Alternatives to Bootstrap
    • Foundation: In the end they are really really similar. He went with bootstrap because it’s from twitter.  They are both really good frameworks and almost do exactly the same thing.  Very similar syntax.
    • There are other frameworks if you just want responsive or something else specific, but most of them do not have the same level of design assistance that bootstrap & foundation have.
Other recommendations for gems, frameworks & tools
  • For hosting he recommended Heroku to start
  • Rails for sure
  • Bootstrap
  • Backbone (optional: it makes the app nicer, but it adds a bit more complexity). You could also use the rails ERB view layer
  • Errors / ticket / bug tracking: RedMine (open source, ruby), Airbrake.io (captures errors in production and sends you an email)
  • Mobile apps:  
    • You need to have an API to do this, so that’s a good reason to go with the javascript client because it forces you to build the API in the beginning.
  • Amazon:
    • http://aws.amazon.com/rds/ >>; Hosted MySQL type data-base. Works really well. Takes care of redundancy and performance. (Heroku has their own mysql / postgres setup.)
  • Mysql vs. Postgres
    • Postgres is completely open source
    • Documentation is better than mysql
    • >> Has he looked into NoSQL / CouchDB? >> He tried to use it but didn't end up doing much with it. (He tried amazon’s dynamodb and also used mongodb.  Look at that if you’re going NoSQL).
      • >> Why use it? > You cannot use it for everything.  Sometimes a relational DB is better.  People use it a lot for high traffic applications.
      • If you use relational you might do a big join to figure out which posts are yours
      • But with nosql you can query an entire document (complete structure).
      • You might have redundant data
      • But accessing it is faster because you don’t have to do joins
      • He would say you could probably do the same thing with caching (like memcache)
    • Rails Gems
Authentication & Social Sign-in
There’s a good rails gem called devise (google: devise gem). It’s the most popular user management / authentication plugin for rails. It works well with the JS client architecture too, but it’s a great gem no matter what.  There are plugins for almost every oauth system you can find (google, facebook, etc)

Good learning resources?
RailsCasts is the best.  Paying for a Pro account is worth it. http://railscasts.com/

Best practices?
There are not many great resources for ralis best practices out there.  The books are ok, but usually they teach you to write unmaintainable ‘spaghetti code”.  
  • For instance: you will see lots of examples where lots of code is in the controller, but it’s often better to put more code into the model layer because it reduces code duplication. (Best practice: lean controller, fat model)
  • Use many gems.  For all of the basic, standard stuff there is a gem available and they’re all pretty good.  (Best practice: Don’t reinvent the wheel)
-----

More Research

After the conversation I did some more research on my own.

Backbone
http://stackoverflow.com/questions/5418369/what-is-the-purpose-of-backbone-jshttp://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/ ;
http://www.jamesyu.org/2011/02/09/backbone.js-tutorial-with-rails-part-2/ ;

>> Determination: Backbone seems too complicated, another thing to learn.  Skip it for now.

Bootstrap
http://railscasts.com/episodes/328-twitter-bootstrap-basics

SASS or LESS?

http://rubysource.com/twitter-bootstrap-less-and-sass-understanding-your-options-for-rails-3-1/ >>; Overview of my options for using bootstrap with rails (NOTE: A little outdated.. 2011)
http://css-tricks.com/sass-vs-less/ ;
>> this one is way better
>> MY DETERMINATION: Stick with SASS.  Both seem fine, but SASS is based in Ruby so I'm pretty safe in picking it.  Additionally, at this early juncture my own instinct is very raw, but the rails tutorial used SASS and that guy is an expert so that's good enough for me.

http://railscasts.com/episodes/329-more-on-twitter-bootstrap?autoplay=true>>; He recommends using simple form (which includes bootstrap support) to get the validation to work without messing up your markup >> More about simple form in episode 264

MongoDB
http://www.railstips.org/blog/archives/2009/12/18/why-i-think-mongo-is-to-databases-what-rails-was-to-frameworks/ >> Note: This one is kind of old (2009) so it's probably pretty out of date.
http://mongoid.org/en/mongoid/docs/installation.html
http://stackoverflow.com/questions/15512683/comparability-issue-rails-4-beta-ruby-2-0-0-mongoid

Heroku specific (MongoHQ vs Mongolab)
https://devcenter.heroku.com/articles/mongohq
>> Determination: Mongo lab has better support (http://webmasters.stackexchange.com/questions/20782/mongodb-hosting-mongolab-vs-mongohq-vs-mongomachine )
>> People on quora (http://www.quora.com/MongoDB/What-is-the-best-mongodb-hosting) also seem to prefer mongo lab .  Higher prices but more reliability or something.

Devise
http://railscasts.com/episodes/209-devise-revised
http://railscasts.com/episodes/235-devise-and-omniauth-revised >>; wow... enabling social sign-in is (while well documented) something of an undertaking. I'm revising this as not an MVP thing.  I'm also looking to investigate a question: What is the point of social sign in??
>> http://blog.mailchimp.com/social-login-buttons-arent-worth-it/

>> The takeaway: Meh... social sign in is DEFINITELY not needed for now. Even if we go for it later a question must be answered first: what is the specific goal of adding social sign in? What do we stand to gain?  How will it make our user experience better?  How will it help the users?

Ruby Conventions
How should I write my Ruby code in order to have it comply with community standards and make it pretty?
https://github.com/styleguide/ruby >>; They have a lot of other style guides too (CSS, Javascript, etc)
https://github.com/bbatsov/ruby-style-guide
Formatting Documentation: http://tomdoc.org/


The End Result - My Decisions

After many days of research and thinking, this is the initial design I went with:
  • Database: MongoDB - I was initially intrigued by not having to do migrations, but what clinched it for me was the argument that relational databases were designed before the advent of web apps and are not properly suited to the task.  It felt true to me: When I think about it there are so many limitations to having to get your data to "fit" into a relational DB.  With document-based databases you can store arrays and hashes and have the flexibility to add new fields at any time.  It just makes more sense.
    • MongoDB gem: Mongoid - It seemed like this gem was more modern.
    • MongoDB host company: MongoLab - This decision was based mostly on a response to a quora question.
  • User Authentication: Devise - Super popular, works with Mongoid.
  • CSS Framework: Bootstrap - Really actively developed, well used, compatible with lots of other gems. Great documentation.  Started by twitter which is a plus for me.
  • Testing Gem: RSpec - What I was used to after the Rails tutorial.