Rails 3.1 - embedding flash.swf files - best practices? - ruby-on-rails

Having problems embedding my .swf file in rails 3.1. In past versions of rails I'd use swfobject and simply do:
<div id="swfbox">you don't have flash</div>
<script type ="text/javascript">
swfobject.embedSWF("swf/AudioRecorder.swf", "swfbox", "400", "400", "10.0.0", "");
</script>
This isn't working in rails 3.1. I'm starting to understand the asset pipeline but I'm still confused where to put the .swf file. So far I've tried of putting everything in /public then /app/assets with a combination using:
<%= asset_path("swf/AudioRecorder.swf") %>

You should be able to put it in any directory you like under app/assets, then reference it with
<%= asset_path("AudioRecorder.swf") %>

Related

Building assets under different paths with Rails and webpacker

I am working on a Rails 5.2.3 application where I have application.js/.css as well as additional files organized into directories as follows:
In my layout I do this:
<%= javascript_include_tag "#{controller_path}/action_name" if File.exist?(Rails.root.join("app/assets/javascripts", controller_path, action_name, ".js") ) %>
I have hundreds of JS and CSS files organized under directories 3-4 levels deep.
After going through the webpacker literature I am still not sure how I am supposed to set it up for this particular use case - it appears entry points must go under app/javascripts/packs but I'm not sure how this webpacker thing can help me at all, am I supposed to go into each view and add individual links to its JS?
How do I get this done?
You can organize your files in the app/javascript folder either under packs or in your own folder structure.
You can then either import into app/javascript/packs/application.js and call it with the <%= javascript_pack_tag 'application" %>.
Or, if you have files in the packs folder you can require single files directly in the view with the same rails helper but the respective file name so e.g <%= javascript_pack_tag 'file_name" %>.

Best way to display images from Rails Asset Pipeline using AngularJS?

I'm working on a Rails app with an Angular-driven frontend. I want to include images from my Rails asset folders into a view that is shown only shown in certain contexts using an ng-switch directive. I tried a couple of solutions, like typing the file path of all other (Rails-served) images into the src of the <img> tag. I also tried adding an erb suffix to the coffeescript file holding the angular controller and then doing this:
$scope.logoSrc = '<%= asset_path("images/logo_grey.png") %>'
and using an ng-src directive in the image tag, but that yielded a 404.
Happy to post more of my code if it's helpful. Thanks in advance for any help!
Try the following:
$scope.logoSrc = '<%= asset_path("logo_grey.png") %>'
According to the section 2.3.3 of the Rails Guides:
If you add an erb extension to a JavaScript asset, making it something such as application.js.erb, then you can use the asset_path helper in your JavaScript code:
$('#logo').attr({
src: "<%= asset_path('logo.png') %>"
});

how do I make public assets in Rails without using the assets pipeline?

I want to bypass the assets pipeline since a very, very silly processing error is completely preventing my app from working.
For example, I want to replace this:
<%= javascript_include_tag 'jquery' %>
with something like
<script type="text/javascript" src="public/javascripts/jquery.js"></script>
How would I go about doing this? whenever I try to use this, the link just ends up pointing to a nonexistent .js file even if I actually put the file in public/javascripts
Remove public, correct path is /javascripts/jquery.js.

Rails - jquery plugin loaded in development but fails to load in production

I have the following in a view:
<%= javascript_include_tag 'scrollable/jquery.tools.min.js' %>
<%= stylesheet_link_tag 'scrollable/scrollable-buttons' %>
<%= stylesheet_link_tag 'scrollable/scrollable-horizontal' %>
Because I have this plugin located in /vendor/assets/javascripts/scrollable/ and /vendor/assets/stylesheets/scrollable/
I don't have any problems in development, but when trying to get into that page in production mode, the JS is not loading. I get this error:
NetworkError: 404 Not Found - https://mysite/assets/scrollable/jquery.tools.min-707bfab8972e8e363a009148db789121.js"
Any thoughts please?
Notice that if I go to: https://mysite/assets/scrollable/jquery.tools.min.js - I can see the code. So I am guessing is some problem with the md5 fingerprint?
sounds like they're not getting precompiled? you can tell by checking if they're listed in public/assets/manifest.yml on production.
if that's the case, and you want to access them via the asset pipeline
did you run rake assets:precompile on production?
did you add the files to the config.assets.precompile array (in config/environments/production.rb)? eg, 'scrollable/jquery.tools.min.js', ditto for css files.
if you don't want to use the asset pipeline, use your own include tags instead of the javascript_include_tag/stylesheet_link_tags, ie <script src="/scrollable/jquery.tools.min.js" type="text/javascript"></script> for the js

What am I supposed to insert in assets generated with controller

I'm playing around with Rails 3.2 and I have noticed that every time I generate a controller, Rails creates a js and css file having the same name in the assets folder.
I'm aware of the introduction of assets pipeline in Rails 3.1 but I'm not sure what code I'm supposed to insert in each of those files.
All the js and css specific for the actions included in the controller? Or how am I supposed to organize my assets?
For example, if you generate a ProjectsController, Rails will also add a new file at app/assets/javascripts/projects.js.coffee and another at app/assets/stylesheets/projects.css.scss. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as <%= javascript_include_tag params[:controller] %> or <%= stylesheet_link_tag params[:controller] %>. See asset_pipeline

Resources