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.
Related
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.
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
https://github.com/memphis518/Garden-Dating-Service
The public repo above is a community coding project we're working on for Austin Community Gardens, and it's a fairly simple project so far, but for some reason rake db:seed doesn't work ("Don't know how to build task db:seed"), and when you run rake -T it reveals no rake tasks at all.
MongoID documentation says it provides most of the usual DB-related rake tasks - I can't figure out why they're not there.
I had the similar problem with Rails 3.X, although the mongoid Gem was included in my Gemfile. I could solve the problem by explicitly requiring the database.rake file from the mongoid gem. I added this 2 lines to my Rakefile:
spec = Gem::Specification.find_by_name 'mongoid'
load "#{spec.gem_dir}/lib/mongoid/railties/database.rake"
That works for me.
Had the exact same issue.
Realized I never added "mongoid" to my Gemfile. This fixes it:
gem 'mongoid'
It will add these rake tasks:
rake db:drop # Drops all the collections for the database for the current Rails.env
rake db:mongoid:create_indexes # Create the indexes defined on your mongoid models
rake db:mongoid:drop # Drops the database for the current Rails.env
rake db:mongoid:remove_indexes # Remove the indexes defined on your mongoid models without questions!
rake db:reseed # Delete data and seed
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, and initialize with the seed data
Is there an environment variable I could leverage in my rails initializers to determine if a rake task is executing ? Like -- rake db:migrate db:seed
I have a bunch of initializers that could be skipped for most rake tasks:
Don't load spring (it's a jruby project)
Don't load the audit observer that breaks the migration
Update:
I'm probably going to regret this later -- but the following seems to work --
In my application.rb -- have added the following:
config.is_rake = (File.basename($0) == 'rake')
Then I am checking for the value later on
config.active_record.observers = :audit_observer unless config.is_rake
Elsewhere in my spring initializer
SPRING_CONTEXT = org.springframework.context.support.FileSystemXmlApplicationContext.new(SPRING_XML_CONFIG_FILES) unless Rails.application.config.is_rake
Based on answer found here
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