Archive for the ‘Ruby’ Category

Amazon Using Ruby on Rails in Production Code

Thursday, December 14th, 2006

Amazon is now using RoR in production code (for an admittedly non-core area of their business):

UnSpun - Community Opionions … Ranked!

Still, I wonder what kind of traffic a link on the Amazon.com homepage drives! (I’m guessing quite a bit)

Via: Signal vs. Noise

Sidenote

Amazon seems like they are really cool with their developers when it comes to letting them choose their technologies. Very Starfishy (just picked this up the other day).

From some of Stevey’s stories, it sounds like they even have some LISP code powering some backend processes there!

Rails Tip of the Day: Refactor In-action Parameter Verification Using the ‘verify’ Method

Tuesday, December 12th, 2006

Let’s say you have a method that looks like this:

 def foo
   if !params[:id] || params[:id].blank?
     render(:text => ‘400 An ID is required for this method. ‘, :status => 400) and return
   end
   … # real action goes here
 end

But you start seeing that same pattern in many different actions, for the same parameters. (:id, usually)

You can instead add this to the top of your controller:

class FooController < ApplicationController
  verify :params => ‘id’, : only => [ :foo, :bar  ],
         :render => {:text => ‘400 An ID is required.’, :status => 400}

  def foo
    … # just do the action, secure in the fact that a
        # params[:id] will be there if it gets to this point.
  end

  def bar
    … # ditto
  end
end

Note: i had to change it to “: only” otherwise a :) would appear there. =) The method also takes :except and a whole host of other options.

The verify method is also used (much more commonly) to require POST, etc. For example:

  verify :method => :post, : only => [ :foo, :bar ],
         :render => {:text => ‘405 HTTP POST required.’, :status => 405, :add_headers => {’Allow’ => ‘POST’}}

Hope that saves you a few extra lines of crufty ‘once-of-prevention’ code =)

Setting up Gruff Dependencies on OS X (RMagick, ImageMagick, etc)

Thursday, October 19th, 2006

Update: Yes! These instructions did the trick.

Gruff is some hot stuff. If you’re working on a Rails app and want to pimp out your backend, or have data that would be much more useful if visually illustrated, it’s the goto tool in the RoR world.

Gruff Example
Example Gruff graph

The only problem I’ve had is getting the whole stack of dependencies installed & working on my PPC mac on OS X 10.4.8.

It seems like plenty of people have been able to get it working, so I’m not sure exactly what’s up.

I spent a few hours one night compiling/recompiling the stack to no avail. (Though, Rubyforge being down that evening didn’t help, either. :))

Just tried this option which says to install RMagick via Darwin ports:

sudo port install rb-rmagick

That didn’t work.

Now trying these instructions… (which, incidentally, weren’t available that night b/c of Rubyforge being down. Maybe it’s the golden ticket!

Wonka's golden ticket

For future Googlers… this was the error I was receiving when trying to build a Gruff graph. I must just not have Postscript/ghostcript or Freetype installed from the looks of it…

sh: line 1: gs: command not found
sh: line 1: gs: command not found
RMagick: no decode delegate for this image format `/var/tmp/magick-HGhhQTrg’.
RMagick: Postscript delegate failed `/var/tmp/magick-HGhhQTrg’.
RuntimeError: Can’t measure text. Are the fonts installed? Is the FreeType library installed?
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/base.rb:875:in `get_type_metrics’
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/base.rb:875:in `calculate_caps_height’
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/base.rb:434:in `setup_graph_measurements’
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/base.rb:397:in `setup_drawing’
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/base.rb:376:in `draw’
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/bar.rb:8:in `draw’
from /usr/local/lib/ruby/gems/1.8/gems/gruff-0.2.3/lib/gruff/base.rb:357:in `write’

Autoload Models in Subdirectories in Edge Rails

Wednesday, October 11th, 2006

If you have models in subdirectories in your Rails app (i.e. app/models/billing/, app/models/observers/, etc), you need to add this line to your environment.rb if you upgrade to Edge Rails:

  config.autoload_paths += Dir[RAILS_ROOT + '/app/models/*/']

Via: I.NFECTIO.US

Plans, Features and A Simplified Approach in Ruby on Rails

Tuesday, September 19th, 2006

Carlos Gabaldon has a slick way of handling plan/feature matrices in this article on Plans, Features and Ruby DSL.

The approach is to encapsulate various features like “can have 15 open projects”, etc. into a ‘features’ table which can house the feature name, etc.

Features in RoR

This allows you to do things like:

if some_model.has_feature?(:can_send_foo)
  # send the foo
end

Nice!

Show, Don’t Tell

Friday, September 8th, 2006

Yes, Ruby does have poor UTF-8 support out of the box.

You might even call Internationalization implementations in Ruby / RoR “hacks”, though they do seem to work quite well by the time the bits get down to the end-user.

I don’t have firsthand experience in doing an RoR internationalization, but it appears that many of the underlying implementation details can be hidden off out of view in your vendor/plugins directory by using the Globalize plugin for Rails.

Ahhh, the beauty of Ruby! It’s shortcomings in one area are made up for by its elegance in other areas.

Shopify Goes International

RoR-powered Shopify now has checkout in multiple languages, even Scottish!

Shopify checkout in German

Robby Russell of Planet Argon responds in the comments as well:

i18n in Ruby on Rails isn’t really that difficult to do. At PLANET ARGON, we have done a few projects that supported multiple languages. The last one that we did supported the following languages:

ENGLISH, ČESKY, DEUTCH, ESPAÑOL (ESPAÑA), ESPAÑOL LATINO, FRANÇAIS, ITALIANO, MAGYAR, POLSKI, PORTUGUÊS (BRASIL), PORTUGUÊS (PORTUGAL), УССКИЙ, TÜRKÇE, าษาไทย, 简体中文
, 繁體中文, 日本語, and 한국어.

We used the Globalize plugin for this.

There you have it.

Via: Riding Rails

Edge Rails: Now With a Built-in XML Sit-ups Ab Machine!

Friday, June 30th, 2006

There’s a lot of innovation still happening in Ruby on Rails.


Rails' New XML Sit-ups Ab Machine

Edge Rails: Now with a Built-in XML Sit-ups Ab Machine!

See this post for some of the things in store for the next major release of Ruby on Rails.

This commenter made a funny XML Sit-ups reference in relation to one of the new features of edge rails:

does the Hash.create_from_xml method mean that Rails does XML sit-ups now?

j/k :) Seriously, this is great.

When it comes time to implement an API in your Ruby on Rails app, well. it already *was* pretty darn easy to do so.

Rails Core & all of the RoR committers just keep making it simpler and simpler to do all this stuff that used to be considered fancy, but is now almost the de facto standard for webapps these days.

Implementing a Billing System in Ruby on Rails vs. ASP

Tuesday, June 13th, 2006

Note: this was written a while back but was sitting in my drafts section. Worth a read if you are coming from a Microsoft background at all.

About two years ago, I implemented a billing system in ASP and SQL Server. It took about a month and a half to get fully flushed out.

Even so, we still experienced intermittent problems with it that drove our salespeople batty. (we could never replicate the problem in-house, since we didn’t have a test lab)

The requirements were, however, different, since we needed to charge cards in real-time in the ASP scenario.

With Sprout, though we might at some point need to do that for certain things (i.e. re-enabling locked, past-due accounts), we generally have the luxury of billing people as needed. (on the backend, at a time of our choosing)

Billing Systems on Rails

The system we just knocked out at Sprout took only about a week. Though, Charles had been working on the requirements for quite some time.

Requirements really do help us programmers. That way I don’t have to idle on IM, asking my manager every 5 minutes about some minutiae of how the system should be implemented.

Yeah - you can always plow ahead and just do things your way… but once you’ve been burned too many times from just doing that, you tend to seek out a little more guidance in the future.

Our system at SproutIt is also a lot more robust than my previous ASP endeavor. Our Sprout system includes a really robust notification system that includes:

- three days worth of charge failed notices
- three days worth of no card present notices
- Activation reminders (signed up for a paid plan, but haven’t entered a card yet, etc)

Hopefully we won’t have to send too many of these various types of notices… but it helps to be prepared.

Rails Productivity Numbers Legit?

Much has been bantied about re: productivity and rails (10x productivity boost, oh my!). Let me just say that I think a 10x number is pure hogwash.

However, even if it were only a 50% increase … that would be incredible. Can you imagine going to a decent manager and explaining that you can get 50% more done if you just use X technology? They would be crazy to ignore that possibility.

In all reality though, I think the number hovers somewhere between 1.5 and 3. That is, you can sometimes get things done in Rails that it would take you three weeks in PHP, or ASP.Net, for example.

Now, Rails productivity vs. Java/J2EE? You’re probably 4-6X as productive in Rails compared to such a bloated monstrosity as J2EE.

Dump and Slurp YAML Data in Rails

Thursday, June 1st, 2006

Topfunky wrote an awesome plugin that allows you to dump and slurp (or, import) YAML data between databases.

This is handy if you have things like a production server & staging server and need to transfer a few records (or whole tables in this case) across the wire.

Another OS X Updated Killed my Symbolic Ruby 1.8.4 Link

Wednesday, May 24th, 2006

Just had to go through these steps again.

Anyone know of a permanent solution? OS X update doesn’t seem to like my symoblic Ruby 1.8.4 link.


You are currently browsing the Shanti's Dispatches weblog archives for the 'Ruby' category.

Shanti A. Braford blogs here.

If you really want to know, just read this.



  

Powered by FeedBlitz