Facebook分享按钮无效?

时间:2016-11-01 12:12:00

标签: ruby-on-rails facebook share link-to

我有房型,我想为facebook创建一个分享按钮。所以我决定用sharer url方法做到这一点。我想在show.html.erb(房间视图)上有一个facebook图标,用户或访问者可以在Facebook上共享房间。当我点击链接时,我被重定向到Facebook,我必须手动输入链接,而不是自动输入我要分享的链接。 如果我要将show.html.erb link_to更新为:

<%= link_to image_tag('facebook_icon_red.png'), 'http://www.facebook.com/sharer.php?u=<%= yield :url %>', :target => :blank %>

然后我收到错误:

enter image description here

我该如何使用?

application.html.erb

<!DOCTYPE html>
<html>
  <head>
...
...
    <!-- for Facebook -->          
    <meta property="og:title" content="<%= @room.listing_name %>" />
    <meta property="og:type" content="room" />
    <meta property="og:image" content="" />
    <meta property="og:url" content="<%= room_url(@room) %>" />
    <meta property="og:description" content="<%= @room.detailed_description %>" />
  </head>

<body>
    <!-- Facebook Sharing Settings-->
    <div id="fb-root">
    </div>
    <script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
    <script type="text/javascript">
    FB.init({
        appId: MY_ID(SOME NUMBERS),
        status: true,
        cookie: true,
        xfbml: true
    });
    FB.Canvas.setAutoResize();
    </script>
...
...
...
  </body>
</html>

show.html.erb(会议室)

...
<!-- Do you like this Accommodation? -->
<%= link_to image_tag('facebook_icon_red.png'), "http://www.facebook.com/sharer.php?u=", :target => :blank %>

FB.ui(
   {
     method: 'feed',
     name: 'Facebook Dialogs',
     link: 'http://developers.facebook.com/docs/reference/dialogs/',
     picture: 'http://fbrell.com/f8.jpg',
     caption: 'Reference Documentation',
     description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
     message: 'Facebook Dialogs are easy!'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
);

1 个答案:

答案 0 :(得分:0)

你的link_to就像这样:

<%= link_to image_tag('facebook_icon_red.png'), "http://www.facebook.com/sharer.php?u=#{yield :url }", :target => :blank %>

这应该适合你。