20120127

Ruby/Rails is confusing for noobs

Here are my questions about Ruby/Rails:

  • After automagically generating the model/view/controller code for a given object, I then want to customize the HTML/CSS/JS for some of its views.  What's the right way to do this?  Do I directly edit the files like "show.html.erb"?  If I do, then don't I lose the ability to automagically update them when I add fields to that object?
  • ERB vs HAML appears to be a religious war... has anyone cleanly summarized the pros and cons?  I would rather not choose randomly, nor spend two hours reading articles about this just so I can decide.
  • Rails 3.2 came out on Jan 20.  Should I use it?  Are Rails releases typically well-tested upon release, or do they typically have bugs that I should hang back and let other people find?
  • Speaking of Rails 3.2, the wonderful site http://api.rubyonrails.org/ seems to have already switched to showing the 3.2 API.  But I'm using 3.1... how can I see the 3.1 API documentation?  Shit, just noticed that http://guides.rubyonrails.org/ switched over to 3.2 as well.  Must I therefore switch?
  • To generate the 3.1 documentation on my own machine, are these the steps I must follow?  http://www.nullislove.com/2007/05/29/rails-documentation/  This post is from 2007, I expect things have changed since then!  Here's more confusing garbage from 2007: http://www.ruby-forum.com/topic/113997  Sadly all the top hits appear to be from 2007.
  • Where do I put the static images that my site is serving?  /public/images or /app/assets/images?  I would like to use image_tag to generate my image tags.  http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html claims that "By default, Rails links to these assets on the current host in the public folder" , but in my own system the generated image_tag has a src of "/assets/img.png" which ends up being served from the directory /app/assets/images.  So, the docs are lying, they are not linked to the public folder.  Or is my setup misconfigured somehow?  Which files in my setup control this behavior?

Here are the meta-questions:
  • Where can I find best-practice source code for non-trivial sites built in Ruby/Rails?  I could then mine that code as a source of examples.
  • Where are the best up-to-date tutorials and references for Ruby/Rails?  Videos don't count because they're not searchable and their effective bit-rate is excruciatingly low, compared to well-written text.  http://guides.rubyonrails.org/ is nice but appears to leave many important questions and issues unanswered
  • Where can I best find out how to do X with Ruby/Rails?  For example I want to use jquerymobile for my UI.  What's the best way to integrate jquerymobile into Ruby/Rails?  Should I use a Gem?  There appear to be three competing gems for this.  And on further inspection they each seem to be pretty trivial, and potentially out of date.

3 comments:

  1. A kind RoR expert referred me to the Pragmatic Programmer books. Many of them are published before 2010, which means they are certain to be out of date in material ways.

    The first Pragmatic Programmer book listed on Amazon is Agile Web Development with Rails. A commenter about it points out "... Rails 3 is changing fast and might not settle down for a little while. A good portion of this book is obsolete. For example, this book still teaches readers to use the Prototype library even though Rails is switching to jQuery in 3.1. Additionally there are numerous other large changes in Rails 3.1 that are not mentioned in this book that will be essential for future Rails developers."

    Argh.

    ReplyDelete
  2. Some answers:

    As far as documentation goes you can find old versions of both the api and the guides at urls like so:

    http://guides.rubyonrails.org/v3.1.1/

    where v3.1.1 is the version number.

    Stick with ERB, it makes things much easier, because it is closer to the final output in syntax.

    Once you scaffold, you have to manually update the files, mostly as you get depper in you'll stop scaffolding so much and just rely on convention.

    And finally the asset pipeline, ah the asset pipeline. Prior to 3.1 assets were served directly from the /public/ path so <%= image_tag 'rails.png' %> would serve from /public/rails.png. They changed all that and now it looks for /app/assets/rails.png, or /public/assets/rails.png It is really confusing, and a breaking change, and i wish they hadn't, anyway you can see how the webserver-rails boundary works here:

    http://guides.rubyonrails.org/v3.1.1/asset_pipeline.html#coding-links-to-assets

    Hope that helps, most of the stuff on internet is old and dated right now -- 2008 was the banner year for rails blog posts -- so it is hard to find resources outside of the guides and reading the source. Best of luck!

    ReplyDelete