如何在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’添加到我的公共目录中并在其中插入了这一行:
- OmniAuth Strategies Facebook NoAuthorizationCodeError(必须传递`code`参数或签名请求(通过`signed_request`参数):
- 使用fb_graph Ruby gem从Facebook检索朋友位置
- Facebook评论插件与rails 4
- 如何通过Graph API在Facebookpost中嵌入链接
- 用户可以使用我的api在第三方网站上通过Facebook注册我的应用程序
- 在很长一段时间的延迟之后,考拉的put_connections()到Facebook图表失败了
- Rails 3 facebook插件/ gem?
- 在Facebook上使用Oauth之后,如何获取用户创建的页面图表?
- 如何从omniauth获取facebook的时区?