Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Yearly Archives: 2011

Johan Ismael

[Standup][SF] 12/30/2011 Moving

Johan Ismael
Friday, December 30, 2011

Ask for Help

“Is there way to test if the Active Record associations you’re trying to eager load with :includes are actually loaded?”

One solution would be to call .loaded on the proxy object which control the access to associations. Another would be to count the sql queries that the block of code makes.

Interesting things

When you query a table with a column containing string values, if you do Model.where(:string => 0) without using quotes for the 0, Rails will not to_s the 0 for you and the query will return the entire table.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Davis W. Frank

Giving Rails 2 the Asset Pipeline

Davis W. Frank
Thursday, December 29, 2011

We had a client project, a Rails 2 app, that needed some cleanup around JavaScript and CSS management. They were using both Sprockets 1 and Jammit, as well as a bunch of plugins and gems to help make all this work together. They had a set of problems that the Rails 3.1 Asset Pipeline solved. But due to gem dependencies we couldn’t go to Rails 3 yet.

How hard could it be to put Sprockets 2 and the Asset Pipeline into a Rails 2 app?

1. Add Sprockets 2

In the Gemfile:

gem sprockets, "~> 2.0"

2. Working with SASS

If you need/want the Sass gem for SASS or SCSS stylesheets, then this goes in the Gemfile:

gem 'sass'
group :development, :test do
  gem 'sprockets-sass'
end

Rails 2 doesn’t include Sass by default. So you need to add it. Yes you might already have Sass if you’re using HAML for your view templates, but since they’re about to be broken apart, add it now.

The sprockets-sass gem adds support of watching individual .sass files in development and recompiling the parent stylesheet asset as needed. It’s not going to be used in production, but more on that later.

For your SASS files you’ll want to use @import to declare SASS dependencies instead of Sprockets’s require.

3. Rack it up in config.ru

Sprockets runs as Rack middleware, but since it’s difficult to map a path in Rails’ environment.rb 2 and make a rackup file. Name it config.ru so that the rest of Rails’s scripts (e.g., script/server) work with it transparently. For example:

What’s going on in this rackup file -

  • Sprockets with the same paths as Rails 3.1′s defaults – add more as necessary for your app
  • Guard against mapping /assets in production.
  • Guard against multiple loads if Rails is already initialized (a fix for testing)
  • Use Sprockets::Helpers to get asset_path and asset_url helpers (and others, see sprockets-helpers) for your stylesheets and views
  • Map / to the rest of Rails, guarding the middleware you don’t need in test

4. More Templates

Using EJS or Mustache? Then drop in the additional gems that work with Sprockets 2′s templating via Tilt:

gem 'ejs'
gem 'sprockets_spacely'

5. Move Your Assets

Now that configuration is done, move your assets under app/assets, just like the Rails Guide suggests. Don’t forget to change the url calls in your stylesheets to asset_url. Run the app, checking your JS console for 404s until all the includes and paths are correct.

6. Capybara

Capybara now needs to forget that it’s running Rails and instead just a Rack app. This technique (WARNING: eval ahead.), meant for using Cucumber/Capybara in a Sinatra app, works.

7. Compile your assets on deploy

All of this work so far makes your assets available from your /app directory in development and test. In production, they will get served from /public/assets. Rails 3.1 provides the assets:precompile to be used as part of the deploy process Generate an empty Rails 3.1 app and copy it into lib/tasks. Copy the Sprockets configuration from your config.ru into this task. Or yes, come up with a way to DRY this configuration up. Then you need to make sure it’s run at the right time during your deploy.

8. What’s left?

This was all we needed and it’s working well for this app. There are a few things that this guide doesn’t cover.

Assets from gems or /vendor are not loaded. Feel free to add explicit paths to Sprockets as needed. The Sprockets Helpers gem doesn’t yet support a Proc for an asset host, but there’s now an open issue on Github. This project didn’t need the former and we threw something together based on Sasset, which appears to be abandoned, and use it only on the asset compile step. We’re not using CoffeeScript on this project. These we’ll leave as exercises for the reader.

The Asset Pipeline is still a bit new and we’re all getting used to it. It’s not just Sprockets, SASS, etc. – there is a lot of functionality that Rails puts on top of Sprockets, but it’s easy enough to add the equivalents.

That wasn’t so bad, was it?

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Johan Ismael

[Standup][SF] 12-28-2011 X-window communication and remote files

Johan Ismael
Wednesday, December 28, 2011

Ask for Help

“What’s the best way to deal with cross-window communication?”

It’s done for now by having the Javascript constantly polling the server. Some other solutions could be using long-polling, websockets (to use websockets with Rails, EM-WebSocket seems to be a good solution). If you have a better answer, Matthew Kocher would be interested!

Interesting Things

“If you want to read remote files, the best way to do it is using GET requests.”

One alternative would be to use run ‘cat filename’ which gives you a text output that you can store. But the issue with this option is that it will add control characters in your text which cannot be parsed and can consequently make everything blow up.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Dan Podsedly

Apigee Pivotal Tracker API Console

Dan Podsedly
Wednesday, December 28, 2011

Apigee, a company that helps you use and develop APIs, just announced a number of new API consoles, including for Pivotal Tracker. The Pivotal Tracker API Console allows you to explore the API from within your browser, and makes it easy to test and debug your code that uses the API. Check it out!

For the rest of the new consoles, see the Apigee announcement blog post.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 12/22/11: Testing javascript is wonderful!

Pivotal Labs
Thursday, December 22, 2011

Hmmmmmm… Interesting!

  • Ever try really hard to get firebug working in your capybara window so you can sleep 1,000,000 in your test and play around on the console?
    If so, you can now use the “capybara-firebug” gem.

  • If you’re trying to optimize your site for different mobile
    browsers, there’s an emulator called “Ripple” that is magic. You can check out what it would look like on various screens, and if you happen to be using PhoneGap you can trigger events.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Private setters in Ruby: What to do?

Pivotal Labs
Thursday, December 22, 2011

Normally, if you have a private method, you can’t call it with an explicit receiver, even if that receiver is self. So you can’t say

def foo
 self.bar  # explicit receiver
end

private
def bar
  123
end

Instead, foo needs to call simply bar, leaving the self implicit:

def foo
 bar  # implicit receiver
end

However, when you call setters, you always need an explicit receiver, or you’ll just assign a local variable:

def assign_things
  self.a = 123
  b = 456
end

def a=(v)
  puts "This one gets called."
end

def b=(v)
  raise "This one never does; the other method makes a local called `b` instead."
end

So, what do you do if you have a private setter? You call it with an explicit receiver:

def assign_things
  self.a = 123
end

private
def a=(v)
  puts "This is called successfully."
end

There’s a crazy special exception in Ruby that lets you use an explicit receiver of self with a setter just so that you can call private setters.

This strikes me as weird. Why can’t you call any private method explicitly on self? I thought it was just easier to implement Ruby if you couldn’t, but if they made it work for setters, I’m not sure what the big deal is.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Erich Douglass

Standup 12-21-2011: Where is my git history?

Erich Douglass
Wednesday, December 21, 2011

Ask for Help

“Is there a good way to manage SQL views using Active Record?”

Check out the rails_sql_views gem.

“Can I move a file or directory with git without having the history becoming disconnected (i.e have to use –follow)?”

Because of the way git stores files, this isn’t really possible. One workaround is to use filter-branch to rewrite history to make it look like the file was never moved. However, you’d have to be careful and ensure that no one pushes the pre-filtered history to the repo after it has changed.

Interesting Things

“It’s not possible to disable 1-click purchasing on a Kindle device.”

Unless you want to have a long chat with your credit card company, make sure you keep this in mind before letting a niece / nephew borrow your Kindle :)

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Erich Douglass

Standup 12/20/2011: Why can’t we all just get along

Erich Douglass
Tuesday, December 20, 2011

Ask for Help

“Is there anyway to prevent Capybara from resetting the session in RSpec?”

Capybara seems to have a reset_session_after_each option. It may or may not be useful.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Alex Lobascio

Standup 12/19/2011: Fun with IE8

Alex Lobascio
Monday, December 19, 2011

Help

JQuery FileUpload + IE8 = Access Denied when trying to upload a file. Turns out the team was styling the file input button to hide the actual file input, but had accidentally given it a width of 1px. The file chooser was working on other browsers because a “choose” event was wired to the actually visible button, which IE couldn’t deal with.

Interesting

IE8 Caching: IE8 will cache responses with 200 response codes. This can be a problem if your user hits a login-required page, gets a 200 on the response to that, logs in, and attempts to revisit the page. Properly setting cache control headers (which Rails does by default) should fix it.

The Heroku Cedar stack uses Ruby 1.9.2.p290. Just sayin’

IE was giving us “Access is Denied” when using the jQuery fileupload plugin and trying to upload a file. We were styling the file input button in the usual way of hiding the actual file input, but at some point somebody had set the width to 1px. The reason the file picker was still working was somebody had wired a “choose” event to the visible button, which worked in all browsers except IE.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Movember Mohawks

Friday, December 16, 2011 | Run time: 2:43

This year Pivotal Labs enlarged the definition of Movember to include mohawks, a mustache for your head. Watch as the SF Pivots get their heads shaved for a good cause! We’re so happy to have raised $40K for prostate and testicular cancer research.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (780)
  • rails (113)
  • testing (88)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (55)
  • techtalk (44)
  • rspec (38)
  • ironblogger (32)
  • productivity (30)
  • activerecord (29)
  • gogaruco (29)
  • git (28)
  • nyc (27)
  • rubymine (26)
  • bloggerdome (23)
  • mobile (22)
  • process (21)
  • pivotal tracker (20)
  • cucumber (20)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • css (13)
  • tdd (13)
  • selenium (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to Community Feed
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. ...
  9. 46
  10. →
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >