I have a room model and I want to create a share button for facebook. So I decided to do this with the sharer url method. I want to have a facebook icon on the show.html.erb (room view) where a user or visitor can share the room on facebook. When I click on the link I am redirected to facebook where I have to enter the link manually and not automatically which I want to share. If I am updating the show.html.erb link_to into:
<%= link_to image_tag('facebook_icon_red.png'), 'http://www.facebook.com/sharer.php?u=<%= yield :url %>', :target => :blank %>
Then I am getting an error:
How can I make this work?
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 (room)
...
<!-- 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.');
}
}
);