Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:33:54+00:00 2026-05-27T15:33:54+00:00

I have a rails 3.1 application where I want to allow users to share

  • 0

I have a rails 3.1 application where I want to allow users to share items via Twitter, Google+ and Facebook (HTML5 version of the like button). I have it working great on the show page for the item (i.e. – just showing that one item), but I’m having issues on a container page that loads the items in a list via Ajax. I want to have separate share buttons next to each item in the container.

The first time the page loads, the share buttons show up fine next to each item. It’s only when I reload the container via ajax that my issue arises. The Twitter, Google+ and Facebook buttons do not show up. Here’s how I have this set up:

application.html.haml

-# This is right before the body tag closes
= render 'site/share_js'

_share_js.html.erb (code from each provider)

<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=MY_APP_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>


<%# Twitter %>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

<%# Google+ %>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

_share_buttons.html.erb (URL of the item to share is passed in)

<div class="share-buttons">

<%# Twitter %>
<a  href="https://twitter.com/share" 
class="twitter-share-button" 
data-lang="en"
data-count="horizontal"
data-text="<%= share_text %>"
data-url="<%= bly_url %>">
Tweet
</a>

<%# Google+ %>
<g:plusone size="medium" href="<%= full_url %>"></g:plusone>

<%# Facebook %>
<div    class="fb-like" 
    data-href="<%= full_url %>" 
    data-send="true" 
    data-layout="button_count" 
    data-width="75"
    data-image="<%= image_path_here %>" 
    data-show-faces="false"></div>

</div>

If I use the share_buttons partial on the item’s show page or the first time the container loads, it works great:

_my_item.html.haml

-# other code here that displays the item...
= render :partial => 'site/share_buttons', :locals => share_info_hash

But, as I alluded to above, it doesn’t work as well after the ajax action:

my_ajax_action.js.erb (called via format.js in the controller)

$("#item-container").html("<%= escape_javascript(render :partial => "my_item", :collection => @item_list)%>");

The items all display correctly in the container, but the share buttons aren’t displaying. I’m guessing that the issue is that provider specific javascript needs to run after executing the ajax action. I’ve tried placing the provider javascript inside the my_ajax_action.js.erb file after the html is refreshed, but this doesn’t seem to do the trick. Does anyone have any ideas on how I could get this to work? Any assistance is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:33:55+00:00Added an answer on May 27, 2026 at 3:33 pm

    The buttons that you are trying to render use a search and replace technique. This works without any special intervention when the elements that become the buttons already exist on the page when onload occurs.

    In your case, though, the elements that become the buttons are inserted after the replace script has executed. Since the order is different than the scripts expect, you’ll need to trigger the rendering yourself after you add the new buttons to your page.

    Here are some links to docs that explain how to do this for each service:

    Google +1 button: https://developers.google.com/+/plugins/+1button/#example-explicit-load

    Facebook Like button: http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/

    Tweet button: Well I can’t find this one in the docs, but based on some forum activity this looks like the code you’re looking for:

    twttr.widgets.load();

    (see relevant forum post here: https://dev.twitter.com/discussions/890 )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a twitter like web application written in Ruby on Rails that allows
I have a rails application what I want to send my users notifications when
I have a non-rails application that I want to use rails active-record migrations with.
I have a Rails application that works with mongodb. I want to deploy it
In a Rails application I have a situation where I want to update the
I want to connect my rails 3 application to firebird database. I have followed
I have an application where users upload images of cars. I want to build
Building a rails B2B application that will have various users. I'm pretty clear on
My Ruby on Rails application uses S3 and Paperclip. I have users upload a
I'm using devise in my rails 3.2 application. I have a users/new page where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.