Articles

Rails on Facebook

by Facebooker plugin committers Shane Vitarana and David Clements

People are spending an increasing amount of time on social networks. Facebook is arguably the most popular worldwide social network and offers a simple API for offering your applications to tens of millions of users with Facebook accounts.

Back on the air!

Hello blogsville!

I think I’ve got things back up and running after an extended vacation from a working Mephisto. We’ll see how it goes.

The startup school talk

I keep getting a flow of positive feedback about the presentation I delivered at Startup School in the Spring. Since it was never linked up here, I thought I'd made sure it made it into the archives: The secret to making money online.

Rails 2.1 introdcution with scaffolding

Apache Abdera supports AtomPub-multipart creation

One of the most weird stuff in the AtomPub specification is the media creation flow. First, you need to send a request in order to post the new media resource and once the response is correct you can update the media link entry related with it.

In order to avoid the second step, the Picassa team added to their api a new way to add photos, and now, they allow to send a multipart file that wraps the photo and its metadata.

Setting up a long term fork with Git

The context

Recently at GiraffeSoft we started a new project, based on another existing project we already had going. We could call this a long term fork. Let me give you a little bit more context on the situation.

Rockstar Memcaching

I’m back from Rubyfringe which was hands down the best conference i’ve been to.

Pete Forde asked me to present on memcached (mem-cache-dee) after my popular blog article Secret to memcached. The talk covers different use cases such as simple html snippet stores to advanced expiry systems such as generational cache keys.

validate positive integer value in model - Ruby on Rails

validates_inclusion_of :some_attribute,

:within => 1..1.0/0,

:message => 'should be positive'

here 1.0/0 it means infinity...

So the attribute is validate within positive. It is done in rails with validates_inclusion_of for numeric data.


Create Application in RoR in specific Rails Version if we have multiple rails installed

cd ..
rails _1.2.6_ test
cd test

here test is the application name... like wise we can cerate any other application in any specific rails version
It happen while we have multiple rails versions in our system...

How to install Rails 2.1 on Ubuntu in 5 steps

I thought it would be a good idea to start with actually installation of rails 2.1, as many latest linux distributions don’t come with the latest version of rails which includes Ubuntu 8.04. So in this how to we will cover installation of rails 2.1 on Ubuntu 8.04.

NOTE: This howto is not for you if you want to be keep your system with ubuntu repository. This howto will use gem to install rails and hence will not use the rails version available in ubuntu repository.

Articles | Rails Fire

Articles

Hello, New York

By way of the obligatory sorry-I-haven't-blogged-much-lately apologette, I should say that life has been busy this summer. The second biggest deal for me was, get this, moving to New York City. Yes, I know I just moved to a new place in San Francisco, and no, I haven't given up on my favorite city. It's a temporary move and I should be back in SF by the end of the year. What happened is that Pivotal Labs has opened an office in Manhattan, and I've come out to work on client projects and help get the office going.

Discovering great tools - qgit

I can’t believe I hadn’t taken the time to try out
qgit yet. Check this out:

rubyMetrics 1.2 supports Rails stats

I've just released the version 1.2 of the rubyMetrcics plugin for Hudson, and I've added support for Rails stats, so, if you check the right option hudson generates the report and its trend graph:

Poor man's migrations

In case you have read PJ’s post on Automatic migrations you might like this.

PoorMansMigrations is a very simple Active Record extension that allows you to create/update/delete DB columns without using migrations directly.

Playing with your models can be as easy as :

Scripting Screen

I do pretty much all my work using GNU Screen inside a terminal. I use a different screen session for each project and have pretty much the same window configuration for each session. After finally getting tired of manually setting up my screen sessions, here’s how I managed to script new session setup.

Ruby Metrics plugin for Hudson

I couldn't keep quiet after I read this Arun Gupta's post, so I've just released the first version of the Ruby metrics plugin for Hudson.

Optimize Firefox’s memory usage by tweaking session preferences

I’m a heavy tabbed browsing user – I have around 30 tabs open in my day-to-day Firefox profile all the time. Since the day Firefox 3 was released, I’ve noticed Firefox progressively getting slower with this particular Firefox profile (I use a different profile for web development). When it got to the point where changing tabs took a noticeable pause of 1-2 seconds, I tweaked some of Firefox’s session store and history preferences and now things are blazing fast again.

Here’s what you can do:

Should(a) cache

Related to my last post about testing cache and some curiosity about Shoulda I made a branch of it to add some helper methods for testing cache generation and expiration:

Boston.rb Slides

The material for the talk is fairly similar to the Lone Star 1.9 talk I did a few days prior, but re-tooled for a smaller group.

Thanks to my employer, FiveRuns, for bankrolling the trip, and to the guys out at Thoughtbot and the Boston.rb group for their hospitality.

When readability is better than metaprogramming

This morning I've bumped into this code:


latitude = phif + (x2frac * x2poly * (x ** 2)) + 
  (x4frac * x4poly * (x ** 4)) + 
  (x6frac * x6poly * (x ** 6)) + 
  (x8frac * x8poly * (x ** 8))

longitude = central_meridian + (x1frac * x) + 
  (x3frac * x3poly * (x ** 3)) + 
  (x5frac * x5poly * (x ** 5)) + 
  (x7frac * x7poly * (x ** 7))

And quickly I've thought that it could be refactored easily with a loop like this:

Shoulda Sporked That | Rails Fire

Shoulda Sporked That

One of the feelings I got from Rails Underground (best not to ask about the others!) is that while RSpec, Cucumber and family have laid tracks in the Rails toolkit and community, many still use TestUnit.

Alternatives are good in some senses, but make me feel like I'm missing out and worry about chasing the wrong rabbit. Seeing things bridged can be nice, and here's an example of that. This one is extra-nice because it also patched what was, to my eyes, a crack in the plaster.

Shoulda for RSpec

I've got some rspec view and controller macros I am considering pulling out into a plugin, but decided to look around for alternatives first. Remarkable is noted on some wiki or other, but I couldn't make much sense of it. rspec_on_rails_macros is a sensible looking alternative, but the origin has been out of development for some time and the forks are somewhat confusing. Looking around did have a positive consequence though -- they pointed out that Shoulda now has rspec support!

That may sound confusing, since Shoulda is another way of writing declarative unit tests (with a similar looking syntax to rspec), but the bonus is a raft of new matchers. So far only the model macros are available but more are promised to come.

Instant gratification:

-    it "should not be valid without a meta description" do
-      Service.make_unsaved(:meta_description => nil).should_not be_valid
-      Service.make_unsaved(:meta_description => '').should_not be_valid
-    end
-    
-    it "should not be valid without meta keywords" do
-      Service.make_unsaved(:meta_keywords => nil).should_not be_valid
-      Service.make_unsaved(:meta_keywords => '').should_not be_valid
-    end
-    
+    it { should validate_presence_of(:name) }
+    it { should validate_presence_of(:teaser) }

I'd Spork That

Next up is Spork, a must-have if you find your specs are running slowly.

You get another executable to add to your workbench, spork, this is a distributed ruby server which uses forking (unix only) to cut down start-up times. Pretty cool I think, get set up to a common starting point then clone it per run.

I find this config works for me, without having to restart the server when I change Machinist blueprints or helper files

require 'rubygems'; require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.dirname(__FILE__) + "/../config/environment"
  require 'spec/autorun'
  require 'spec/rails'
  require 'shoulda'
  require 'webrat'

  Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].each do |file| 
    require file 
  end

  # Requires supporting files with custom matchers and macros, etc,
  # in ./support/ and its subdirectories.
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

  Spec::Runner.configure do |config|
    config.use_transactional_fixtures = true
    config.use_instantiated_fixtures  = false
    config.fixture_path = RAILS_ROOT + '/spec/fixtures/'

    config.include Webrat::Matchers, :type => :views

    #machinist setup
    config.before(:all)    { Sham.reset(:before_all)  }
    config.before(:each)   { Sham.reset(:before_each) }
    #end machinist setup
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.
  require File.expand_path(File.dirname(__FILE__) + "/blueprints")

  Spec::Runner.configure do |config|
    config.include ViewHelpers, :type => :views
    config.include ControllerHelpers, :type => :controller
    config.extend ControllerMacros, :type => :controller
  end
end

I went the route of adding --drb to the spec.opts file. This works with textmate and autospec. If you forget to run spork it'll run locally without the drb.

If you want something more (or actually) distributed for your tests take a look at testjour, or even some of the cloud computing services (which I've forgotten the names of!).