23 responses to “Embedding SWF content with Ruby on Rails”

  1. srboisvert

    Nice. Unlike every other example on the web this one actually worked for me!

  2. Andy Stewart

    This was exactly what I needed. If only all the web was this useful!

    Thanks.

  3. Cliff

    Glad I can be of assistance :-)

  4. Meekish

    Or in pure Ruby, if that suits your fancy: http://agilewebdevelopment.com/plugins/flashobject

  5. Cliff

    Very cool, I’ll add that to the article. Thanks Meekish!

  6. Ngetha

    Hey.

    Been checking out your past works. You are great in flash! Kudos!

  7. stewie

    Hi. If I would like to protect the Flash (swf) files from unregistered users? Any ideas how that could be done ? Not talking about the authentication/authorization part, but how could I render SWF files or something like that instead of having them in public directory ?
    thanks.

  8. Cliff

    Hi Stewie,

    Take a look at the send_file function in your controller, which will obscure the true location of your SWF. This function will send the data in chunks of 4096 bytes, so it’s pretty efficient to use for these purposes.

    Then all you need do is point your SWFObject to /path/to/controller/action (e.g. /media/swf?file=foo.swf) and job done :-)

    More info here: http://www.rubyinside.com/railstips/tag/send_file

  9. Amit

    Hi

    i use in view

    and how to rest of the parameter
    my file location is
    http://122.169.104.164:3002/video_screenshots/logo.flv
    how to show that in the view
    Thanks
    amit Agarwal

  10. dave

    I cannot get this to work at all. I have read through the google page and blog completely. The page just sits there and stares at me…. no flash playback. (The div never gets the flash player loaded into it).

    I am hosting at bluehost.com, but that shouldn’t matter. I placed all the files where there articles say to… (so far after 6 months of intense development at bluehost, everything else tends to work as RoR standards indicate it should.)

    I even tried using the (longer) swfobject.js in the src subdirectory. No use.

    Here is my reduced-to-its-simplest web page
    http://me2you.client-express.com/mtyuser/tpl0
    in case you want to see the trivial code behind it. I have verified the da_player.swf file is in
    #{RAILS_ROOT}/public/swf and permissions look okay…

    Any ideas?

  11. dave

    You helped me get it working, but it isn’t working quite the right way: Your clue about direct access to the SWF file led me to getting that located and working, but in order to do that I have to insert a default route in the routes.rb as:
    map.connect “*anything”,:controller => “mtyuser”, :action => “swf_handler”

    then in the controller I put an action:
    def swf_handler
    p = params[:anything]
    if p[1] == “da_player.swf”
    send_file(“#{RAILS_ROOT}/public/swf/da_player.swf”);
    end
    end
    to serve out the swf file.

    AND it only works with the standard Flash script (Adobe’s AC_RunActiveContent.js), not the swfobject advocated on this site. I still cannot get that to work yet. I think it cannot find the videoplayer skin.

    I will spend more time on this, but for right now wanted to get you a reply status and a big thanks for getting me past that hump.

  12. Steve

    Hi Cliff

    Thanks for the blog post. I’m pretty new to this and have run into trouble. I took your code and just added the name of my swf file where you had:
    “/swf/my_swf.swf”, “my_swf”
    I have my flash file in the swf directory under public. Is there something I’m missing.

    Thanks for your help!

    Steve

  13. skiN

    This is really simple and very good. Thanks a lot!!!

  14. satya

    tx a lot. U saved my day ! and nit too ;)

  15. julien

    Hey man :D

    I keep on reading this page each time I have to work with Rails and swfs (yeah, work is interesting these days :)
    I wanted to ask you if this could work in partials?

    TY

  16. julien

    OK, sorry for double posting, I’m impatient as usual, it works, you’re the man :p

  17. Marc-Andre

    Good page. Just to let you know that SWFObject is now at version 2.1 and has moved to http://code.google.com/p/swfobject/

    I’ve upgraded the flashobject plugin to use this new version of SWFObject and made it more “rails-like” with swf acting like other assets. It’s all on github: http://github.com/marcandre/swf_fu

    Thanks!

  18. Velu

    hi, i got a prob while running the swf i got an error=> SWF OBJECT UNDEFINED…
    can anyone tell me how to rectify it..
    i’m new to Ruby on Rails

  19. John

    Cliff, this is just what I am looking for but am having problems. I am new to flash and rails that I am working with. I followed your steps – when I run I get the alternative message displayed rather than a flash screen. I do have flash installed.
    As an aside I also tried using the swf_fu plugin but that is not working either. A very frustrating afternoon.

Leave a Reply