Reputation: 2290
In my project, I have tried to bundle most of my js libraries into gems so they can be updated and pulled in whenever necessary, however, I've recently setup our production server and I'm having issues with asset compilation and static assets in /public/assets.
Specifically, when I don't use the asset pipeline, I have no issues with datatables or any other JS libraries or css that I am trying to use. I am precompiling my assets in production and using a typical nginx setup (based on railscast #335) to serve them.
Static assets are the following -
public/assets
javascript/jquery.formatCurrency-1.4.0.min.js
stylesheets/datepicker.css
twitter/bootstrap/bootstrap-datepicker.js
is public/assets the correct place for these?
When I deploy with capistrano, these assets get a 404 when loading the page and are not actually copied to the /public/assets directory on the server.
When loading other pages I am calling the datatables plugin as follows
$('#inventory_item_list_datatable').dataTable
sDom: "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
sPaginationType: "bootstrap",
iDisplayLength: 100
Datatables is compiled into my application.js and doesn't throw an error, but the table never actually renders. I'm wondering if this is related to the order that everything is compiled?
app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require jquery_nested_form
//= require twitter/bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap
//= require_tree .
app/views/layouts/application.html.erb
<%= stylesheet_link_tag "application", :media => "all" %>
<link href="/assets/stylesheets/datepicker.css" media="all" rel="stylesheet" type="text/css" />
<%= javascript_include_tag "application" %>
<script src="/assets/twitter/bootstrap/bootstrap-datepicker.js" type="text/javascript"></script>
---edit datatables issue
when using jquery-datatables-rails gem it must be OUTSIDE of your assets group in gemfile.
Upvotes: 2
Views: 1105
Reputation: 4315
By default , asset-pipeline comes with 3 locations for placing the assets : app/assets
, lib/assets
and vendor/assets
. You have to place (in case you'd like to rely on the pipeline) your assets there , not in the public/
. In the production env all the assets are compressed and transformed into one file (respectively for .js
and .css
) : application.*
.
EDIT : In this case the assets
directory was structured differently . After the chat with @theIV and @Kosmonaut , we have found the solution : moving the assets to the vendor/assets
directory with structure :
For Javascript assets:
vendor/assets/javascripts/specific_javasripts
and for CSS:
vendor/assets/stylesheets/specific_stylesheets
By default , the vendor/assets/
directory does not contain javascripts
nor stylesheets
directories , they should be created .
Upvotes: 1