Rails 3 showing Twitter Button in success notification
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 a开发者_JAVA百科dd 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...
This answer worked for me and I now have a twitter button showing with the success flash message! :)
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)) }
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
精彩评论