How to write a channel.html file in Rails (for Facebook)

According to the FB SDK I must include a channel file with the appropriate headers.

Being a major NOOB and a Rails not PHP developer I have no idea how to do this.

Here is the example they provide for php:

 <?php
 $cache_expire = 60*60*24*365;
 header("Pragma: public");
 header("Cache-Control: max-age=".$cache_expire);
 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
 ?>
 <script src="//connect.facebook.net/en_US/all.js"></script>

I want to know how do I do the same thing in Rails 3

Answers


Use the response.headers hash in your controller. Docs

Example from your example

cache_expire = 60*60*24*365
response.headers["Pragma"] = "public"
response.headers["Cache-Control"] = "max-age=#{cache_expire}"
response.headers["Expires"] = ... # I'll leave this one to you.
                                  # (Or ask another Q.) 
               # gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');

I got tired of polluting my routes.rb file in every facebook connected app so I wrapped a rack handler that gives the correct channel.html response in a Rails Engine and published it as a gem. You can simply include the 'fb-channel-file' gem in your Gemfile and it will be automatically mounted at /channel.html https://github.com/peterlind/fb-channel-file


Inside your controller:

cache_expire = 1.year
response.headers["Pragma"] = "public"
response.headers["Cache-Control"] = "max-age=#{cache_expire.to_i}"
response.headers["Expires"] = (Time.now + cache_expire).strftime("%d %m %Y %H:%I:%S %Z")
render :layout => false, :inline => "<script src='//connect.facebook.net/en_US/all.js'></script>"

Need Your Help

Data structure for searching strings

c# string search tree

I am looking for the best data structure for the following case:

json and vb.net 10

json vb.net

I am making a program that should collect the same information from different json.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.