Really Easy 'Facebook Like' for Rails


I don’t think anyone noticed, but I’ve had Facebook Like done wrong on my site for a few weeks. I had pasted in their boilerplate code, not noticing that the URL was encoded in there already as Duh.

I made myself a little helper that should work well for everyone. It automagically inserts the current page (using request.url) and encodes it for you. Just put this in your application_helper.rb

          def facebook_like
            content_tag :iframe, nil, :src => "{CGI::escape(request.url)}&layout=standard&show_faces=true&width=450&action=like&font=arial&colorscheme=light&height=80", :scrolling => 'no', :frameborder => '0', :allowtransparency => true, :id => :facebook_like

Then on any page you want Facebook Like, just include this:

<%= facebook_like %>

Easy! Go ahead and ‘like’ this page, please :)

You must join to comment. Join now!