dashing-rails
dashing-rails copied to clipboard
Issue while compressing JS files with the Asset Pipeline
Hi,
I'm trying to run rails-dashing under passenger-nginx and i Get this errors:
GET http://foo.com/dashing/widgets/r.html 500 (Internal Server Error) application-3587576a36c1ab2a24c5687247faf363.js:3 Uncaught Error: Could not load view from /r application-3587576a36c1ab2a24c5687247faf363.js:13 GET http://foo.com/dashing/widgets/u.html 500 (Internal Server Error) application-3587576a36c1ab2a24c5687247faf363.js:3 Uncaught Error: Could not load view from /u application-3587576a36c1ab2a24c5687247faf363.js:13
Of course widgets 'u' and 'r' doesn't exist and are not defined anywhere
I set the js compressosr as YUI and even leave raisl to serve the assets in real time (like in dev) but not lucky. I also added the options suggested to run it under apache:
rails_app_spawner_idle_time 0; passenger_min_instances 1;
Any clue will be welcome
TIA
Yes I ran into the same issue when deploying on Heroku. I had to:
- Add
gem 'yui-compressor'
to theGemfile
- Set
config.assets.js_compressor = :yui
inconfig/environments/production.rb
- Run
RAILS_ENV=production bundle exec rake assets:precompile
localy
Letting Heroku run the asset precompile command even with yui
compressor set did not work. I think in you case, the issue is definitely the JS compression since the widgets' name are guessed base on their class name, which no longer works when JS compressor change the class names to shorter ones.
I don't know much passenger
so I don't think I could help you more here :(
thanks, but it did't works for me.
exactly same steps, but i'm precompiling in the server (is a VPS not heroku). The only that works for me is to create links to the original widget:
r.html -> /usr/local/rvm/gems/ruby-1.9.3-p448/gems/dashing-rails-2.1.1/app/views/dashing/widgets/number.html
This is very weird, you should be able to control how the asset pipeline compress your JS files. It's not an issue directly related to dashing-rails gem sicne it would work nicely if the JS files are just compressed but variables name beeing not modified.
Please let me know if you figure out a way to make it work.
Its not ideal but I had the same issue, I fixed it (temporarily with)
class NoCompressor
def compress(string)
string
end
end
at the top of production.rb
then
config.assets.js_compressor = NoCompressor.new
basically, disable js compression (I didn't look very hard to try and find a proper way to disable it)
a hack for sure but it got me one step further :)
Thanks for the feedback!
Let me close the issue since it's not really a bug from the gem and we now have identified where does the issue come from.
Please keep us posted we you find anything.
IMHO is not good idea to lose this bug. Is easy to find it if it is open, and this workaround disable compression in the whole rails app, not only dashing, so it is actually a requirement to use rails-dashing.
Yes I see, i'll digg into this issue to see what can be done.
Hi guys,
I've run in to this problem today. I'm working on setting up dashing-rails at the moment so if anyone can provide me with any info I can take a look at fixing it. It's the end of a long shift here so I won't be looking at the problem right away.
Ta, James.
Basically the issue comes from the JS compressor when precompiling the assets on production. The default JS compressor seems to also change JS variables and class names (from Foo
to f
for example).
Since the widget's name are used to fetch their HTML template from the server (making a GET request), having their name changed cause the issue.
In order to get around this issue for the moment, you need to change the default JS compressor used when compressing the assets.
I have done the above for the heroku demo application by following the following steps:
- Add gem
yui-compressor
to theGemfile
- Set
config.assets.js_compressor = :yui
inconfig/environments/production.rb
- Run
RAILS_ENV=production bundle exec rake assets:precompile
locally to force Heroku to use my local precompile assets
I will look more closely to this issue since I was recently told that the default JS compressor should not change .coffee
class names. I'll keep you guys posted and push any fix if necessary.
If you guys want to take a look at it. Here is where I use the JS widget name to get its HTML template on the server side https://github.com/gottfrois/dashing-rails/blob/master/app/controllers/dashing/widgets_controller.rb#L29
All we have to do is to make sure the name coming from the params
matches the widget HTML file name which seems to not be the case at the moment because of JS compression.
Thanks @gottfrois. I'll have a look at this once I'm back in the office.
Seems that by default uglifier will mangle variable and function names.
The documentation seems to suggest that you can do something like
config.assets.js_compressor = Uglifier.new(mangle: false) # Uglifier.new(:mangle => false) for old Ruby
https://github.com/lautis/uglifier#usage
I will run this when I get a chance but feel free to jump in there before me.
I'll try that tonight, thanks for digging in to this issue.
Ok setting Uglifier.new(mangle: false)
works. Let me add this to the readme. Not sure how we should handle this though. Any ideas ?
Thanks for looking at it.
Sorry for the long wait. Nothing comes to mind immediately. I won't have much time to look at this in the coming weeks but if you leave any thoughts on this thread I'll investigate them once I'm back on the dashboard project.
Thanks.
@brightbits thanks for your tip! This was perfect for my application since it's just a rest api.