Every facebook example is always written first in php. For example, detecting a fan.
Some are never translated. For the record, here's a rails version. This goes in the controller (or even better, a helper).
p = params['signed_request'].split('.')
json = Base64.decode64(p + "=" * (4 - p.size % 4))
data = ActiveSupport::JSON.decode(json)
liked = data["page"]["liked"]
Note the encoded string needs to be padded with = signs until it's a multiple of 4 bytes long.
The background on this is facebook has disabled static/fbml tabs from being added to fan pages. Instead, create an app and add the app to your page. This is to cover what people used to do with the fb:visible-to-connection fbml tag.