opal-rails in Rails 5 does not add fingerprinting to assets? - assets

I've precompiled my assets with
RAILS_ENV=production bundle exec rake assets:precompile
And run my rails app as:
rails s -e production
But my app does not request
application-{fingerprint}.css
application-{fingerprint}.js
Instead it request without fingerprint.
What could I missed out? Or is this a Rails5 bug. I have no issues with Rails4.
Updated:
I've found the problem to be caused by opal-rails.
As I've create my app with the following command
rails new MyApp --javascript=opal --skip-active-record
Starting in production does not add fingerprinting to assets with opal-rails.
It works fine with jquery-rails.

Related

uninitialized constant Rails::Command::Actions::APP_PATH (NameError) when trying to start Rails engine server

The full error is
~/.gem/ruby/2.4.0/gems/railties-5.1.5/lib/rails/command/actions.rb:8:in `set_application_directory!': uninitialized constant Rails::Command::Actions::APP_PATH (NameError)
I recently upgrade from Rails 4.x to 5.x.
You need to generate (or regenerate) "binstubs" for the dummy application.
cd spec/dummy
bundle exec rails app:update:bin
You should now be able to start the dummy application, from the spec/dummy directory, as such:
bundle exec bin/rails server
The spec/dummy/script directory can also be deleted.

Unable to access config.handlebars in production mode

I've got an existing rails app, and I've added an ember front-end. I'm having trouble deploying the new version (which includes Ember for the first time) to Heroku.
The problem is that I'm unable to run rake tasks in production mode.
I discovered this when I tried to rake db:migrate on heroku. I got the following error:
rake aborted!
undefined method `handlebars' for #<Rails::Application::Configuration:0x00000004f0de90>/app/.bundle/gems/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configuration.rb:85:in `method_missing'
/app/config/application.rb:60:in `<class:Application>'
I get the same error if I try to run any tasks locally in production mode, e.g.:
RAILS_ENV=production rake -T
the offending line, from config/application.rb:
config.handlebars.templates_root = 'ember/templates'
for various reasons, I had to move the ember templates down one file level. and it needs to stay there. everything works fine in development mode.
Any idea how I can fix this?
tried upgrading the ember-rails gem. this didn't help. (I'm using 0.12.0)
trick was to move ember-rails gem out of assets group

Rails 3.2.11 asset precompile fails if threadsafe! enabled

I'm on Rails 3.2.11 and ruby 1.9.3.125
My app is working ok in devel and production if threadsafe! off
With threadsafe! enabled I get an error during precompiling, in my asset
assetsolutions.js.erb (which is the main js file of the application) I use the
Workorder class as in the next line
if ($('#workorder_worktype').val()=='<%= Workorder::REPAIR %>')
with threadsafe! the class can't be found at precompile time, I've done some reasearch and I think it may be related with rails switching off eager loading if threadsafe! is on
How can I include the Workorder class to make precompile work?
error follows:
c:/rails3/ruby/bin/ruby.exe c:/rails3/Ruby/bin/rake assets:precompile:all RAILS_
ENV=production RAILS_GROUPS=assets
rake aborted!
uninitialized constant #::Workorder
(in C:/rails3/applications/assetsolutions/app/assets/javascripts/preloaded/ass
etsolution.js.erb)
C:/rails3/applications/assetsolutions/app/assets/javascripts/preloaded/assetsolu
tion.js.erb:763:in `evaluate_source'
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [c:/rails3/ruby/bin/ruby.exe c:/rails3/Ruby...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Tnx
Fabio
I just had the same issue on a Rails 3.2.13 application and I solved it by adding config.eager_load = true to my config/environments/production.rb file. This also solved eager loading issues I had with rake not loading models.

Routing error while searching for javascript

My app worked a few days ago.
I have switched to 'thin' from webrick
now I get
2011-12-28T07:08:53+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/jquery.livequery-6725741b06c676d9173d5056b277caeb.js"):
I saw on other question that they were told to set this to true
config.serve_static_assets = false
but heroku recommends against that.
I have tried both using rake assets:precompile locally and then pushing and also without it and let heroku precompile.
Both give same error
How do I make sure the javascripts are served, compiled and available?
Why is the error occuring?
I'm using rails 3.1.3 on cedar, Latest Thin.
I was able to solve this using the question Rails 3.1 asset precompilation - include all javascript files
so.. problem solved

Global access to Rake DSL methods is deprecated

I am working through the Ruby on Rails 3 tutorial book and typed the following on the command line:
rake db:migrate
which produced the following warning.
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/imac/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
I am not sure what to do about it or how to work with it. I don't know any other command for Rake.
How can I fix this problem?
Adding include Rake::DSL to the Rakefile before the applications load_tasks were called also worked for me.
So in the above user's case before the DemoApp::Application.load_tasks in the Rakefile.
I found this in Stack Overflow question Ruby on Rails and Rake problems: uninitialized constant Rake::DSL. It refers to a #DHH tweet.
Put the following in your Gemfile
gem "rake", "0.8.7"
You may see something like
rake aborted!
You have already activated Rake 0.9.1 ...
I still had a copy of Rake 0.9.1 in my directory so I deleted it.
You can "delete" Rake 0.9.1 by running the following command:
gem uninstall rake -v=0.9.1
If you have multiple versions of the gem installed, you'll be prompted to pick a version.
After 0.9.1 was cleaned out, I ran
bundle update rake
and was finally able to create my database files. I was using rake db:create, but it should work for rake db:migrate as well.
I hope it helps.
I was having the same problem on Windows with the installer. Ruby 1.9.2 and Rails 3.0.9.
Here is what I did:
bundle update rake
bundle show rake
After doing that I was running rake 0.9.2.
Then I updated the Rakefile in application root folder as follows:
require File.expand_path('../config/application', __FILE__)
require 'rake'
# If you named your application something other than SampleApp, change that below
module ::SampleApp
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
SampleApp::Application.load_tasks
As noted in the comment, make sure the name of your app is correct in the two appropriate lines above.
If you are seeing this on later versions of Rails (like 3.+) you may also want to verify that your environment is clean by using RVM http://beginrescueend.com/ and creating a specific ruby & gemset for your projects.
Use an .rvmrc file on a per-project basis, this will guarantee you aren't getting older system gems into your projects. Which has bitten me before.
This prevents having to monkey around with generated Rakefiles & such.
bundle exec rake db:migrate will solve your ruby version issues