How to make FB Comments social plugin dynamic

Alex, I am experimenting with adding FB comments to each show page. I did successfully, but its showing all comments from other show pages. Here is the code: <div class="fb-comments" data-href="http://localhost:3000/models" data-width="600" data-numposts="5"></div>. I know this is because my href is for everything. Any idea on how to make the href for each model? Here is my attempt:<div class="fb-comments" data-href="http://localhost:3000/models/#{model.id}" data-width="600" data-numposts="5"></div>. But I got no luck. Perhaps you have a better take on it. Thanks.

Posted about 4 years ago by Jeremy Molayem
Posted about 4 years ago by Jeremy Molayem

Its the URL that needs to be dynamic.

1
Posted about 4 years ago by Alex Yang

This is somewhat beyond the scope of BaseRails (and I haven't set up the Facebook comments plugin before), but if you just want to make the URL dynamic, you can use ERB in your 'data-href'. Something like this:

<div class="fb-comments" data-href='<%= "http://localhost:3000/models/#{model.id}" %>' data-width="600" data-numposts="5"></div>

Hope that helps!

1