开发者

Where should flash files be stored in 3.1?

In Rails 3.0.X, I would store my flash files in public/flash. Flash files such as: jwplayer, uploadify, etc.

With the introduction of the new directory structure in 3.1 (i.e. app/assets/), should flash files still be stored in public/flash or should I create a new directory called 'flash' in a开发者_如何学运维pp/assets/ ?


You can use the Sprockets provide directive.

For example, this is how I am using Plupload:

# app/assets/javascripts/plupload.js
//= require plupload/plupload
//= require plupload/plupload.flash
//= require plupload/plupload.silverlight
//= provide plupload/dependencies

The corresponding vendor directory is organised like this:

vendor
├── assets
│   ├── javascripts
│   │   └── plupload
│   │       ├── dependencies
│   │       │   ├── plupload.flash.swf
│   │       │   └── plupload.silverlight.xap
│   │       ├── plupload.flash.js
│   │       ├── plupload.js
│   │       └── plupload.silverlight.js
│   └── stylesheets
└── plugins

I then use <%= javascript_include_tag 'plupload' %> when I want to use Plupload, and use the asset_path helper to populate the Plupload configuration:

<%= javascript_include_tag 'plupload' %>

<script type="text/javascript">
$(function() {
    var uploader = new plupload.Uploader({
        runtimes : 'flash,silverlight',
        multipart : true,
        multipart_params : {
            'authenticity_token' : '<%= form_authenticity_token %>'
        },
        flash_swf_url : 
            '<%= asset_path "plupload/dependencies/plupload.flash.swf" %>',
        silverlight_xap_url :
            '<%= asset_path "plupload/dependencies/plupload.silverlight.xap" %>',
        url : '<%= url_for [@item, :photos] %>',
        // ...
    });

Hope that helps.


if these are .swf files, I don't think they belong in app/assets. The asset folder allows for pre-"compiled" app asset files for CoffeeScript and SCSS (or similar js and css "compilers"). If you are compiling .as files into .swf files as part of your deploy or startup process, I could see it making sense to put them in the asset folder. However, this seems like a horrible idea.

=================UPDATE=====================

I was wrong. The asset folder is for serving Sprockets assets. As long as you can handle digested asset paths you should use Sprockets.


I think, there are good arguments for both places. Using the asset pipeline (store them under /app/assets) has the disadvantage, that cannot hard link any static files from the flash, since you cannot tell the filename in production (Rails will add a hash sum of the content to the file name). You will have to generate flashvars or xml files with Rails containing the resource filenames.

However, if you use the asset pipeline, each file will get a new hash sum in its file name, if the file changes. You can tell the browser to cache the files forever, because once you reference a changed file, it will be new to the browser (<- file name) and it will load the changed file from the server. Caching will make your site faster for returning visitors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜