0

In my Rails 3 web app, I show a success message when someone updates their profile. With this code: redirect_to @user, :flash => { :success => "Profile updated." }

What I want to be able to do is show a Twitter button, which is an a href and javascript see here

How would I add it to the success flash? I have tried just copying and pasting the code but I then get errors basically saying syntax is wrong...

Thanks in advance...

3 Answers3

1

This answer worked for me and I now have a twitter button showing with the success flash message! :)

Community
  • 1
  • 1
0

You would do something along the lines of this:

redirect_to @user, :success => "Profile updated.", :flash => { :url => "<a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>" }

And in the layout:

- if flash[:success]
  ## Display code, etc...
  - if flash[:url]
    = flash[:url]

Or something along those lines

nbucciarelli
  • 460
  • 2
  • 6
  • 16
  • I modified the code to this `redirect_to @user, :flash => {:success => "Profile updated.", :url => "Tweet" }` and it shows this: http://i.qyk.in/381d3d74.png –  Jun 10 '11 at 18:24
  • I have changed the `"` to `\"` and visa versa but it's still shows the html link as text, not an actual link. –  Jun 10 '11 at 18:26
0

You might need to wrap your twitter code in a raw method to force it to not escape the html and an escape_javascript method to force it to escape the javascript

So try something like this

redirect_to @user, :flash => { :success => raw(escape_javascript(twitter_code)) }
Kelend
  • 1,417
  • 2
  • 11
  • 18