Simple Object Embed Tags for Ruby on Rails
I really dig SWFObject in Javascript for making nice lightweight flash objects. What I really need, much more often though, is a way to present any Flash, Movie, Game, Song, or Thing easily in a view, and for it to be just like any other ActionView Helper.
So here is what I use, probably more often than any other plugin (except acts_as_authenticated)
./script/plugin install svn://ahgsoftware.com/simple_object/trunk |
It’ll take whatever arbitrary parameters you give it, however, I’m lazy as hell and I just call it with no parameters, and let the code handle inferring decent defaults (although for video/image/swf you’ll want at least the width/height). Here’s how I use it.
1 2 3 4 5 6 7 8 9 |
simple_object '/swfs/game.swf' simple_object '/songs/test.mp3' simple_object '/swfs/mp3player.swf',:url=>"/mp3s/tool.mp3" simple_object 'test.mov',:width=>"640",:height=>"480" # and so on.. |
I’ll be adding support for more filetypes shortly. Enjoy!
January 13th, 2007 at 09:29 AM Works lik a charm ! Thanks
January 24th, 2007 at 09:58 PM Hi; Shared host doesn't allow svn. Is there another way I can get your plugin?
January 24th, 2007 at 10:59 PM
I checked it into a public directory for you!
./script/plugin install http://www.ahgsoftware.com/downloads/simple_object
I'll get webdav working soon, I didn't even think about the problem of Shared Hosts! Thanks.
April 4th, 2007 at 06:16 AM This is handy! One limitation though, is that if your app is running as a subdirectory of the site root (eg using the mongrel --prefix option), it doesn't add the prefix on for you, so the link points to the wrong place.
April 5th, 2007 at 08:50 AM
I wasn't sure what the expected behaviour would be for that case actually. The way I use it (which seems like a standard way of doing it, don't quote me on that!) is by, using relative urls for your sources e.g.
<table class="CodeRay"><tr> <td title="click to toggle" class="line_numbers" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"></td> <td class="code">simple_object_tag 'songs/test.mp3'</td> </tr></table>And then, setting the prefix the 'rails' way in environment.rb with this..
<table class="CodeRay"><tr> <td title="click to toggle" class="line_numbers" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"></td> <td class="code"></td> </tr></table>That, of course, assumes that 'testing' is the --prefix that you provided for mongrel!