-1

I am adding fb shared button in application using the docs at Share Button. Its working fine, but I want to share the current page's URL in facebook. For example:

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-type="button"></div>

I want to fill my current URL href section, how can i achieve this

http://localhost:3000/news/view/2

This is my URL, here id changing each time, instead of developers.facebook.com how can I add my URL id here.

jww
  • 97,681
  • 90
  • 411
  • 885
XYZ_deve
  • 475
  • 5
  • 6

3 Answers3

3
request.original_url 

will return current url. refere this link for more info.

Alok Anand
  • 3,346
  • 1
  • 20
  • 17
  • @priyank patel and alok anandh, i want to current news article page in facebook in application..how can i change my code there in href section – XYZ_deve Apr 05 '14 at 10:45
  • 1
    @Ullas you mean to say that you want something like href="https://developers.facebook.com/docs/plugins/2" – Alok Anand Apr 05 '14 at 10:47
  • ,yes i am running in local host my news application, i want to share this news,news are in differnt id eg: http://localhost:3000/news/view/2 – XYZ_deve Apr 05 '14 at 10:51
  • @XYZ_deve [Answered below](http://stackoverflow.com/a/22879886/1376448). Does that help? – kiddorails Apr 05 '14 at 10:54
  • 1
    @XYZ_deve ok, if you want href like this href="https://developers.facebook.com/docs/plugins/2", do this href="https://developers.facebook.com/docs/plugins/ + #{params[:page or article whatever it denotes 2]}" – Alok Anand Apr 05 '14 at 10:56
  • @Alok thanks, i mean page not like that,i want to share my current article (news) page in fb..for that wat i have to do. – XYZ_deve Apr 05 '14 at 11:07
  • @XYZ_deve "http://www.facebook.com/sharer.php?u="+request.original_url or "http://www.facebook.com/sharer.php?u="+request.fullpath.... – Alok Anand Apr 05 '14 at 11:13
  • @AlokAnand my question similar to this, http://stackoverflow.com/questions/18458635/request-original-url-in-fb-comments-div but am not getting result, can you please help me – XYZ_deve Apr 05 '14 at 11:57
2

Rails > 3.2 request.original_url

Rails 2: request.url

Found SO Questions you can refer this and this :) .

Community
  • 1
  • 1
Priyank Patel
  • 3,495
  • 20
  • 20
2

Use request.original_url and change that code as:

<div class="fb-share-button" data-href="<%= request.original_url %>" data-type="button"></div>

As per Share Button Documentation, data-href parameter contains the URL which one wants to share, above will just do the same.

<%= %> embeds and evaluates Ruby code inside your template. So, it will enable you to share your current page using FB share.

Hope that helps

kiddorails
  • 12,961
  • 2
  • 32
  • 41
  • Even the other link you specified uses same method; I see no reason why it shouldn't work. Can you update the question with the markup generated after u made the above change? – kiddorails Apr 05 '14 at 13:45
  • Its coming facebook share page,inside full of empty..there is no error showing..i want to share my current news ,which contain differnt id.. – XYZ_deve Apr 06 '14 at 04:14
  • 1
    @XYZ_deve It's little hard to decipher what you want to convey with that. Can you update your question with the screenshot of the screen and pastebin the complete HTML markup of that corresponding page? It may help us :) – kiddorails Apr 06 '14 at 06:18
  • can i get your any kind of chat id,can you please help me to solve this problem – XYZ_deve Apr 07 '14 at 01:31