如何在Rails中编写channel.html文件(适用于Facebook)

根据FB SDK,我必须包含一个带有相应标题的通道文件。

作为一个主要的NOOB和Rails而不是PHP开发人员我不知道如何做到这一点。

以下是他们为php提供的示例:

  

我想知道如何在Rails 3中做同样的事情

在控制器中使用response.headers哈希。 文件

示例中的示例

 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 MYH:i:s', time()+$cache_expire) . ' GMT'); 

我厌倦了在每个facebook连接的应用程序中污染我的routes.rb文件,所以我包装了一个机架处理程序,在Rails引擎中提供正确的channel.html响应并将其作为gem发布。 您可以在Gemfile中简单地包含’fb-channel-file’gem,它将自动挂载在/channel.html https://github.com/peterlind/fb-channel-file

在您的控制器内:

 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 => "" 

我只是将’channel.html’添加到我的公共目录中并在其中插入了这一行: