Do your Jasmine tests (or anything else) seem to lock up when they aren't the active tab in your browser?

Unfortunately, your new and modern browser is to blame. There are a few workarounds, but none of them are ideal in my opinion.

Interesting

  • When using validates on an association, remember for uniqueness validations to use the associated attribute.

    validates :foo, :uniqueness => true
    

    Should be

    validates :foo_id, :uniqueness => true
    
  • You can get a quick an easy git blame with a string, rather than a line number.

    git log --pretty=oneline -S'some string'

Help

  • What is the advantage of using scope over a class method?

    scope :new, order(:id)
    

    or

    def self.new
      order(:id)
    end
    

    Some Pivots seem to think that scope doesn't add the default scope in some cases (a bug?). It appears that class methods are the preferred way moving forward in Rails.

Events

  • Tuesday brown bag was a series of Youtube videos of Alan Key speaking about programming.
  • Thursday UX Book Club is meeting to discuss Steve Jobs book.

Jimmy LiJimmy Li
Longest Standup Ever
edit Posted by Jimmy Li on Wednesday February 29, 2012 at 10:03AM

New Faces

David, Mark, and Melinda are here from a client. Kyle is interviewing.

Helps

"Simple form translates labels. How do we get this to work in nested models?" Check yesterday's email for answers. "Dev Bootcamp is teaching people how to program, the Pivotal way. They're looking for mentors - contact Will if you're interested. Also, Sarah is going to visit them tomorrow (Thurs) over lunch. Let her know if you want to tag along."

  • Does anyone know how to integrate with Google analytics using Garb (Google Analytics for Ruby). Jonathan would love to chat with you.*
  • Is there a commonly accepted javascript date library? * Check out strf-time.js; it's an easy way to format dates and times. It doesn't respond to daylight savings time in the right way, though, so watch out for that.

Also, Date.js (but it might fight with ember)

  • Does anyone know of a good worker system? * Simple worker is one option. Others?

Interesting Things

  • In Rails 3.2 now drops your namespace out of your automatically generated form classes. Make sure this doesn't screw up your CSS!
  • If Postgres keeps printing out warning messages for you whenever you interact with your database, place "min_messages: warning" into your database.yml file and it will shut up.

*Get your time in! *Gold conference room is now totally hooked up. Please don't play around with the cables yourself. *Brown bag lunches will be on Tuesday, starting next week. *JSHint got pulled from RubyGems, so point your Gemfile to its github account instead.

Andrew BruceAndrew Bruce
SF Standup - February 28th, 2012: what does i18n stand for?
edit Posted by Andrew Bruce on Tuesday February 28, 2012 at 09:29AM

Requests for help

"simple_form i18n labels for namespaced models i.e. Foo::Bar"

The requester wasn't around, but we assumed the namespacing causes problems. No suggestions except "don't namespace models"...

"On Ruby 1.8.7, Jasmine is timing out on startup after 60s. The project has a lot of fixtures and tests. Mongrel seems to block itself and then waits. Any ideas?"

A lot of blank faces.

Adam BerlinAdam Berlin
NYC Standup - February 27th, 2012
edit Posted by Adam Berlin on Tuesday February 28, 2012 at 07:15AM

Interesting

Monit + 'check program' + Zombies

from Dave Goddard

Monit recently introduced a new type of service to check ; "check program" which will run a script each cycle (or specified number) and will end up being good or bad depending on the exit code. After we started using this, we noticed that the script was often marked as a zombie on the machine ; at first we blamed the script, but eventually discovered that this is expected behaviour by monit, and that monit is planning to fix it RSN (real soon now)

Polymorphic Associations and Active Record Subclasses

from Adam Milligan

If you have a polymorphic association, Rails will use the base class of the parent of the association (as defined by ActiveRecord) as the class name of the associated parent.

For instance:

class Foo < AR::Base
  belongs_to :wibble, polymorphic: true
end

class Bar < AR::Base
  has_many :foo, as: :wibble
end

class Baz < SomeSubclassOfActiveRecordBase
  has_many :foo, as: :wibble
end

The class of the wibble association when instantiated for Bar will be Bar.

The class of the wibble association when instantiated for Baz will be SomeSubclassOfActiveRecordBase, not Baz, unless SSOARB.abstract_class returns true.

Jimmy LiJimmy Li
SF Standup 02/27/12
edit Posted by Jimmy Li on Monday February 27, 2012 at 07:56PM

New Faces

Elliot is here today

Helps

"How can I place stuff over flash plugins in the DOM? (z-index problem)" You can place iframes on top of the flash plugin, or set the transparent attribute on the flash elements to true. There should also be a jQuery plugin that handles this.

Interesting Things

  • Ruby meetup tonight. People who are staying around for it should try to help set things up.
  • Poltergeist: a headless capybara driver that uses phantom.js. Check it out. Rick has used it with great success.

Hunter GillaneHunter Gillane
Boulder Standup - Feb 24, 2012
edit Posted by Hunter Gillane on Friday February 24, 2012 at 07:25AM

Helps

  • RubyMine 4 is scrolling to the bottom of the window when displaying test results.

Click the gear in the test runner window and click "Select First Failed Test When Finished"

Interestings

  • grep_routes Tyler from Boulder office mate Everlater wrote a gem called grep_routes. It lets you search your routes without loading all of Rails. Only works with Rails 3.1 and 3.2.

Gregg Van HoveGregg Van Hove
Standup 02/23/2012 - Charts are cool
edit Posted by Gregg Van Hove on Thursday February 23, 2012 at 09:15AM

Ask for help

  • A team is migrating from PaperClip to CarrierWave and while the site seems to work fine, however tests are failing in strange ways. Specifically, tests about replacing images aren't saving any changes to the database, but there are no validation errors.

  • What javascript charting libraries are cool?

The easy recommendation was HighCharts (http://www.highcharts.com/)

And there is also D3 (http://mbostock.github.com/d3/) but it is much more low level

Interesting things

  • According to Amazons AWS newsletter, S3 now has 762 billion objects and is serving 500,000 requests per second.

Gregg Van HoveGregg Van Hove
Standup 02/22/2012: Apache trying to compete with Nginx?
edit Posted by Gregg Van Hove on Wednesday February 22, 2012 at 09:12AM

Ask for help

  • Where are the cool parking garages around the new office?

There appear to be many options close by.

  • What is the best way to estimate hosting costs? (e.g. how many dynos on heroku etc.)

One suggestion was to try load testing the app in the real hosting environment to get an idea on what you can realistically take.

Interesting Things

  • A new version of Apache has been released that is trying to compete better with nginx

You might call this post Part 2 in a component based architecture series. The first post describes a solution for better organizing loosely-coupled, highly-cohesive components within a singe Rails application.

This post describes a component based solution that aims to support vastly different user experiences and client side strategies across multiple web applications that share a common domain while allowing developers to work independently within individual web applications or components.

Here's the scenario...

You're tasked with building a fairly large web application, several user roles each packed with handfuls of high-level activities. The larger application could clearly be broken apart into smaller web applications. It's a clear win to break things down. The smaller applications would have unique responsibilities and developers could work within the context of one application without worrying about introducing breaking changes across applications. However, the smaller applications, although independent, share a common domain or database.

You start thinking about how you'd expose subsets of the domain as RESTful services and maybe introduce a single sign-on approach, although you're concerned about managing, versioning, and deploying multiple web applications and services, not to mention how this might impact the early development rhythm. There's no clear path to success, so you write the classic uber app.

The tide could be changing in your direction. Here's a solution that's shown early success for developing and deploying large Rails applications: move loosely-coupled, highly-cohesive web applications and components to a components directory within a container Rails project.

Until recently such an approach might be difficult to imagine. Although, with the addition of mountable engines in the latest versions of Rails, the approach is now possible. Here's an example that describes the project structure...

container_rails_app/
  app
  config
  components/
    component_1/
      lib/component_1.rb
      lib/component_1
      test/lib
      test/test_helper.rb
      Gemfile
      component_1.gemspec
      Rakefile
    component_2/
    component_3/   
    web_app_1/
      app
      config
      test/lib
      test/test_helper.rb
      Gemfile
      Rakefile
    web_app_2/
      app
      config
      ...
  ...

The container application simply mounts dependent web applications as Engines, exposing each with their own context or url. Engines in turn reference in any Engines or Gems they depend on.

However, there is one twist, we keep everything in a single Git repository.

Engines are organized as prescribed within their corresponding directories, although they're not built nor do they have their own Git repository. They're referenced directly from the containers Gemfile.

As database migrations trigger sweeping changes, the refactorings become simpler and you don't need to worry about deploying updates to multiple applications/services as all your code is in one place, versioned together.

As important, each Engine or Gem has it's own Gemfile, test_helper, test suite, and continuous integration environment. As mentioned in the first post, the unique Gemfile and test helper allows you to remove unnecessary dependencies while the individual test suite and continuous integration environment helps to avoid circular dependencies.

Other articles: