Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 - assets precompile, but not display in production mode with Apache

Edit: Turns out my initial question is no longer accurate - the issue isn't directly related to the dataTables gem, I believe it's to do with my Apache2 configuration.


I seem to have an issue with the jquery-datatables-rails gem playing nicely with the rails asset pipeline.

The problem at first appeared similar to this one, but following the apparent path of solutions from there didn't happily resolve the issue.

The gem is in my Gemfile, installed and implemented for one of my html tables according to the directions in railscast episode #340. Running the application in development mode with bundle exec rails s works just fine, and all of the dataTables features appear on the site with no problem.

When I try and run the site in a production environment - either using capistrano or just bundle exec rails s -e production - after precompiling the assets, the compiled files aren't used, though they do all compile to public/assets.

It also didn't seem to show dataTables features when using config.assets.compile = true in lieu of precompiling. (I believe the two are opposites, but I may have misunderstood)

There are no errors when I go to the page and view the js error console, it just renders a plan html table.

I can not figure out what's causing the webpage to not render dataTables, and every search I've tried has wound up at the question linked above plus some five other pages over and over again. None of those solutions seem to have been what my rails beast is hungering for.

Do any of you fine people have any insight as to what the problem might be?


Parts of some relevant files:

app/assets/javascripts/charts.js.coffee:

jQuery ->
    $('#charts').dataTable({
      "oSearch": {"bSmart": "true", "sSearch": "vdo"}
      "iDisplayLength": 50
     })

app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require_self
//= require_tree .

app/assets/stylesheets/application.css

*= require_self      
*= require dataTables/jquery.dataTables
*= require_tree . 

config/environments/production.rb:
PerfGrapher::Application.configure do # Settings specified here will take precedence over those in config/environment.rb

# Compress JavaScript and CSS
config.assets.compress = true

# make sure to compile js and css assets
config.assets.precompile += %w(*.js *.css)

# Generate digests for assets URLs
config.assets.digest = true

# disable static asset server
config.serve_static_assets = false

config.compile = false

end

like image 504
scrattatat Avatar asked Nov 09 '12 21:11

scrattatat


1 Answers

My application.css.scss file has the following line

*= require dataTables/src/demo_table_jui

instead of

*= require dataTables/jquery.dataTables

This may only be because I'm using JQuery UI also (with bJQueryUI: true being passed to dataTable() in the coffeescript file)

It works fine in production, with the asset pipeline, using Rails 3.2.6.

like image 134
Alex Blakemore Avatar answered Nov 04 '22 18:11

Alex Blakemore