views:

158

answers:

1

In my main controller, I have this:

class MainController < ApplicationController  

  before_filter do |controller|
    logger.info "controller.request.format.html? = #{controller.request.format.html?}"
    logger.info "controller.request.format.fbml? = #{controller.request.format.fbml?}"
    controller.send :login_required if controller.request.format.html?
    controller.send :facebook_auth_required if controller.request.format.fbml?
  end

As expected, I get "true" for the ...fbml? line if a request comes from Facebook (my facebooker gem automatically sets the format). However, I get "5" for the ...html? line if the request comes from Facebook. Why would a method with a ? ever return a "5"? Isn't that against Rails conventions? Also, I think "5" is considered true so this might mess up my filters. Still looking into that...

Any ideas?

A: 

The only things that evaluate to false in Ruby are false and nil. Here's a great lightning talk from last year's RubyConf that pretty much explains it all in less than seven minutes: The Nature of Truth

Sarah Mei