【问题标题】:how to add facebook comments to a rails application如何将 Facebook 评论添加到 Rails 应用程序
【发布时间】:2013-01-13 02:25:20
【问题描述】:

我有一个用 ruby​​ on rails 创建的简单博客,我的模型包括 帖子,类别和分类。也就是帖子通过分类属于很多类别

post.rb

class Post < ActiveRecord::Base
   has_many :categorizations
   has_many :categories, through: :categorizations
  attr_accessible :author, :description, :title, :photo, :category_ids    
end

category.rb

class Category < ActiveRecord::Base
  attr_accessible :name
  has_many :categorizations
  has_many :posts, :through => :categorizations
end

分类.rb

class Categorization < ActiveRecord::Base
  attr_accessible :category_id, :position, :post_id
  belongs_to :post
  belongs_to :category
end

应用程序中没有用户模型 我希望能够在帖子模型中添加 facebook 评论,以便访问我的应用程序的任何人都可以对任何帖子发表评论,而且我还可以计算出最高 facebook 评论的帖子,以便我可以利用它

【问题讨论】:

    标签: ruby-on-rails facebook comments


    【解决方案1】:

    你可以看看这个宝石,https://github.com/intridea/omniauth 你可以使用这个 gem 做很多事情,并且可以存储在你的数据库中。

    【讨论】:

      【解决方案2】:

      阅读this

      你只需要在你的应用中加入这样的东西

      <div id="fb-root"></div>
      <script>(function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=504323752911178";
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));</script>
      

      Place the code for your plugin wherever you want the plugin to appear on your page.

      <div class="fb-comments" data-href="http://example.com" data-width="470" data-num-posts="2"></div>
      

      data-href 是您帖子的网址

      【讨论】:

      • 感谢您的回答,我如何在开发环境中进行测试??
      • 非常感谢它对我有用,但我现在的问题是如何计算每个帖子的 cmets 数量?
      • &lt;fb:comments-count href=http://example.com/&gt;&lt;/fb:comments-count&gt; awesome comments 这将发出 55137 awesome comments
      猜你喜欢
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 2011-07-09
      • 1970-01-01
      相关资源
      最近更新 更多