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!

5 Responses to “Simple Object Embed Tags for Ruby on Rails”

  1. Peter Says:
    Works lik a charm ! Thanks
  2. sporb Says:
    Hi; Shared host doesn't allow svn. Is there another way I can get your plugin?
  3. Michael Cerna Says:

    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.

  4. Ashley Moran Says:
    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.
  5. Michael Cerna Says:

    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">
    ActionController::AbstractRequest.relative_url_root = "/testing"
    </td> </tr></table>

    That, of course, assumes that 'testing' is the --prefix that you provided for mongrel!

Leave a Reply

 

Michael Cerna Chicago-based Rails Developer and Avid Musician. More ...

Search

Categories

  • Home (15)
  • Rails Plugins (5)
  • Pages (9)
  • Archives

    Tags

    BlogRoll