AssetNotPrecompiledError when using html5-rails gem in production env - ruby-on-rails

I've got html5-rails and compass-html5 working in devlopment on rails 3.1 but when I run my app in production mode and try to visit my homepage, I get the following:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index
polyfills.js isn't precompiled
The thing is that localhost:8080:/assets/polyfills.js does display. I suspect there is a problem with my methods:
Steps to reproduce:
1 Create new rails app with home controller, index action and set up a root route and delete public/index.html and views/layouts/application.html.erb
2 Add following to Gemfile
gem 'rails', '~> 3.1.0'
gem 'unicorn'
group :assets do
gem 'compass', "~> 0.12.alpha.0"
gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'compass-html5', :git => 'https://github.com/sporkd/compass-html5.git'
gem 'html5-rails', :git => "https://github.com/sporkd/html5-rails.git"
end
3 Run rails g html5:install to create /config/compass.rb file
4 Create /config/initializers/sass.rb containing following code:
Rails.configuration.sass.tap do |config|
config.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
end
5 Run RAILS_ENV=production bundle exec rake assets:precompile
6 Run unicorn -E production (or rails s -e production if you're on webrick) and visit root url
7 Observe bug
The correctly minified respond-md5.min.js and modernizr-md5.min.js are present in /public/assets. The compiled js code does appear when I visit localhost:8080/assets/modernizr.min.js. The server error is thrown when I try to visit my homepage.
I suspect there is an error in my method. I have asked the very same question here on github.

I managed to fix this by adding polyfills.js to application.rb
config.assets.precompile += %w( polyfills.js )

i just got the same error, and the issue was that my file was missing...

Related

Spree Routes Not Working after Database Reset

I recently had to reset my development database (because of Spree migration complications) and now some of my Spree routes seem to be missing.
I have the following Spree-related gems:
gem 'spree', '>= 4.3'
gem 'spree_auth_devise', '~> 4.0'
gem 'spree_gateway', '~> 3.6'
I have this in my routes.rb file as the only spree-specific route...nothing custom:
mount Spree::Core::Engine, at: '/store', as: 'spree'
However, when I go to http://localhost:3000/store I get an error saying No route matches [GET] "/store".
This is especially strange because when I run rails routes the first thing that comes up is:
Prefix Verb URI Pattern Controller#Action
spree /store Spree::Core::Engine
I have run rake spree_auth:admin:create and created (and confirmed) an admin user, if that helps.
Can anyone see why my Spree isn't appearing?

Rails database configuration does not specify adapter. What do I do?

The following is the error message:
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
...
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
My database.yml file:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
My Gemfile:
source 'https://rubygems.org'
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"
gem 'jquery-rails'
gem 'devise'
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
gem 'mini_magick'
gem "rmagick"
gem "carrierwave"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
I solved a similar problem in a somewhat intricate project. Not sure it's directly related, but I'm posting this as the way of debugging the problem may be helpful.
In my case, I had the following scenario:
The situation only occurred when RAILS_ENV=production. When I did RAILS_ENV=development it worked. Weirdly enough, when I changed the production entry in database.yml to production2 and ran the command with RAILS_ENV=production2, it worked.
In the project I was connecting to multiple database connections through various models and libraries.
Here is what I did to detect the issue:
vim /Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb
(or wherever the backtrace is telling you the issue is).
Then, I found the place in the code that has these lines:
def resolve_hash_connection(spec) # :nodoc:
spec = spec.symbolize_keys
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
And changed it to the following:
def resolve_hash_connection(spec) # :nodoc:
spec = spec.symbolize_keys
# Debug printing
puts "*" * 80, spec.inspect, "*" * 80
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
Then I reran the command, in my case bundle exec rails c production.
By doing this I realized that Rails wasn't looking for the production entry as I was thinking it was. It was looking for a different entry called abc_production, which was required in my project due to the multiple database connections I was referring to earlier. On that particular server someone forgot to add that abc_production entry to database.yml. Adding the entry solved the issue.
I believe it happened only when RAILS_ENV=production because in environments/production.rb I have config.eager_load = true, which means Rails will eager-load the application and classes to memory, and probably attempt to establish all database connections defined in those classes (one of them being abc_production).
Hope this helps someone in a similar situation... If you're not using multiple connections, try and debug the problem by changing connection_specification.rb and see if it gives you any lead..
i don't now exactly what you tried to do but.
currently i got the same error as i tried to run < rails c -e production > with ruby-2.10.
`resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
as i run < rails c production > everything works.
maybe this helps someone
I had a similar issue with staging environment and I did:
added devise secret to devise.rb initializer file
configured staging 'secret_key_base' in secrets.yml
It worked fine me there after.
I've crated an gist with a sample database configuration, please make sure you use it.
The gist is located at: https://gist.github.com/fidalgo/5970617
Also make sure you run rake db:setup to setup your database.
Also since in your environment you are using Sqlite for production and test too, in your Gemfile change this lines:
group :development, :test do
gem 'sqlite3'
end
to
#group :development, :test do
gem 'sqlite3'
#end
it shouldn't make any significant difference, except you are using other environment than development.
I met this problem too. I tried all similar questions I can find but none of them resolved my problem then I tried to print configurations system read from database.yml in activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb
def resolve_string_connection(spec) # :nodoc:
hash = configurations.fetch(spec) do |k|
connection_url_to_hash(k)
end
p configurations
p spec
raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash
resolve_hash_connection hash
end
The output is
{"production"=>nil, "  adapter"=>"mysql2", "  encoding"=>"utf8mb4", "  username"=>"myUsername", "  password"=>"myPassword", "  pool"=>5, "  database"=>"mydb", "  host"=>"myHost", "  port"=>3306, "mydb_production"=>nil}
So my problem is there's something wrong in the database.yml causes YAML parse error. However I don't find anything wrong by my bare eyes so I copied a file from another server then problem resolved.
Hope this can help someone :p
Realise this is a little old, but have just come across whilst looking for an answer on a similar issue. Just wanted to point out that you still have sqlite3 as your adaptor in your .yml. As you have probably found out since, Heroku does not allow sqlite3 as a production db. SQLite on Heroku

Why do I get an AppFog Rails Error 310: Staging failed: Staging task failed?

I'm trying to push a Rails application to AppFog and I keep getting a 301 error.
It gets to Staging, so it shows up on my AppFog account, but refuses to activate. Trying to update it succeeds, but has the same problem where it won't activate and only shows a 404 error.
Here is the message text:
$ af push RubyMongoGranny --runtime=ruby193
Would you like to deploy from the current directory? [Yn]:
Pushing application 'RubyMongoGranny'...
Creating Application: OK
Binding Service [ruby_mongo_granny]: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (236K): OK
Push Status: OK
Staging Application 'RubyMongoGranny': ..........Error 310: Staging failed: 'Staging task failed:
Staging plugin failed: /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_task.rb:325:in `log_and_raise_error': Error resolving Gemfile: Error parsing Gemfile: /tmp/d20130401-19438-h0d0st/Gemfile not found (RuntimeError)
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_task.rb:50:in `specs'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_task.rb:103:in `gem_info'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/gemfile_support.rb:86:in `gem_info'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:188:in `rails_version'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:199:in `precompile_assets'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:85:in `block in stage_application'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:76:in `chdir'
from /opt/cloudfoundry/vcap/staging/lib/vcap/staging/plugin/rails3/plugin.rb:76:in `stage_application'
from /opt/cloudfoundry/vcap/stager/bin/run_plugin:19:in `<main>'
My gemfile looks like:
source 'https://rubygems.org'
gem 'rails'
gem 'mongo_mapper'
gem 'bson_ext'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'cloudfoundry-jquery-rails
==UPDATE==
Changed
config.server_static_assets = false
to
config.server_static_assets = true
and precompiled my assets?
bundle exec rake assets:precompile
but it still gives me the same error.
Changed
gem 'jquery-rails'
to
gem 'cloudfoundry-jquery-rails'
still no success
Did you change in your config/environments/production.rb
config.server_static_assets = false
to
config.server_static_assets = true
and precompiled your assets?
bundle exec rake assets:precompile
Also, for Ruby 1.9 AppFog requires a tweak to the jquery-rails gem. Remove or comment out gem 'jquery-rails' and add gem 'cloudfoundry-jquery-rails', like so:
# gem 'jquery-rails'
gem 'cloudfoundry-jquery-rails'
Further documentation here.
Didn't really come up with a good solution for this problem. However, I created a brand new rails app and moved all of my files from the old one to the new one. Now it will push to AppFog.
I did a diff of the directory, but all the differences are just log files, the app name, and the readme file. Nothing really stands out as a possible cause of the error.

icon-globe not found after update gem twitter-bootstrap-rails

I'm using twitter-bootstrap-rails gem. Last night I updated my gems, and tried using the icon-globe but all i got was an empty space.
here are my Gemfile:
gem 'jquery-rails'
gem 'therubyracer'
gem 'mongoid'
gem 'bson_ext'
gem 'bson'
gem 'mongo'
gem 'devise'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
I tried rake tmp:clearbut this didn't worked too
I just ran into this the other day as well. I have my Rails servers setup so that I can run multiple Rails apps on the same server under their own suburi. Apparently the asset-path helper in the bootstrap_and_overrides.css.less is not including the relative path for the sprites and instead points the background-image url to /assets instead of /suburi/assets.
Following what I found here: https://github.com/rails/rails/issues/3365 I was able to gather that I needed to do the folllowing when precompiling assets:
RAILS_RELATIVE_URL_ROOT="/suburi" rake assets:precompile
This sets the relative root within the environment when you precompile and everything then works as it should.
The thing that really threw me for a loop was that in development everything worked just fine. As soon as I pushed it to the production server the icons stopped showing up. I kept thinking there was an issue with my server or my code. All along it was just the asset-path helper not including the suburi when I precompiled my assets.
Just set your full suburi path in the RAILS_RELATIVE_URL_ROOT environment variable before running the precompile and it will work.
Update: You can set this variable in the config/application.rb file by adding
config.action_controller.relative_url_root = '/suburi'
This would be the best option as it would not require extra typing when deploying.
You can read about it here:
http://guides.rubyonrails.org/configuring.html#configuring-action-controller
did you try:
bundle exec rake assets:precompile
on your production environment?

Upgrading from Rails 3 to Rails 3.1 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do you upgrade from Rails 3 to Rails 3.1 beta?
This is what worked for me when updating an existing rails 3.0.8 project. Your mileage may vary...
Update the rails version specified in my Gemfile to use the latest release candidate:
gem 'rails', '3.1.0.rc4’
Update the bundle:
bundle update
Then update the project with the rake command:
rake rails:update
After cherry picking though the change conflicts I ran all my tests and they passed (yay!). I restarted the server and everything seems good so far.
However, this is not using the new asset pipeline yet. By that I mean the javascript and css (or sass) files are still being handled in the pre-pipeline manner. As I understand it, this is a perfectly viable option. But of course, I want the new goodness, so I believe the next steps are to include and additional gems (e.g. coffeescript, sass, uglifier, etc) and then to migrate the old files to the app/assets directory.
I found some details about that are here:
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
Hope that was helpful.
I just upgraded from 3.0 to 3.1 by changing my Gemfile to:
gem 'rails', '3.1.0.rc1'
gem 'sqlite3'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
I also commented out the following line below in config/environments/development.rb
# config.action_view.debug_rjs = true
Finally, make sure you enable the asset pipeline in config/application.rb
config.assets.enabled = true
I'm not sure if you've already read the release notes http://weblog.rubyonrails.org/2011/4/21/jquery-new-default
Upgrading Rails
Update: be cautious of using your system rake, as rake has been upgraded.
bundle exec rake
ensures you'll be using the correct rake for a given rails project (source)
I suggest beginning with a fresh app, then copying in your specific app information while shifting your resources into the new asset/sprockets format.
An example
While converting an older rails 2.3.4
app to 3.0 I crashed and burned while
changing one file at a time over
within the project. Needless to say
that was a flawed strategy, but I did
learn a little along the way. I ended
up skipping 3.0 and moving to 3.1beta1
with a fresh app, and copied my app
and public folders in after getting
the migrations right. That move had a
couple of outstanding issues, the most
important being that I didn’t use
rails edge for creating the new app
(thanks for the tip RubyInside).
First snag the latest rails into an
easy to reference location:
cd ~/goodtimes
git clone
https://github.com/rails/rails.git
My path includes a ~/Desktop/Dropbox/
so my code is available everywhere.
Then refer to that rails exec for
building a new app:
~/goodtimes/rails/bin/rails new bacon --edge
Depending on the complexity of your database, you'll either want to create new migrations using the change syntax or leave them be:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
I had an issue deploying to Heroku, but theRubyRacer gem helped square that away. Here's an example of a simple Gem file:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'pg'
gem 'therubyracer-heroku', '0.8.1.pre3', :platforms => :ruby
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I suspect there will be community utilities to help you automate migration from older versions of Rails to the --edge.
References:
How to Play with Rails 3.1, CoffeeScript and All That Jazz Right Now
The Four Horsemen of Rails 3.1beta, Coffee-Script, jQuery, SCSS and Assets
Rails 3.1beta deployed to Heroku from your iPhone
Reversible Migrations
I recommend updating your Gemfile to use edge rails. For example:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
gem 'uglifier'
You can read more here http://pogodan.com/blog/2011/04/24/easy-edge-rails.
If i understood your question correctly this is how:
gem install rails --pre

Resources