I am currently following 'Ruby on Rails Tutorial' by Michael Hartl. On Chapter 3 when I try to deploy the working sample app with Heroku it is rejected, and even though I fully understand the error message I do not know how to correct it. Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.5'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
And here is the file where the issue originates which is config/environments/development.rb:
SampleApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
The errors I get are attempting 'git push heroku master':
Running: rake assets:precompile
rake aborted!
NoMethodError: undefined method `configure' for #<SampleApp::Application:0x007fc7f03f7298>
and after a long list of paths I get:
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:some-name.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:some-name.git'
Any idea how to fix this please? I really would like to get deployments working under Ubuntu.
Thank you!
By default Rails 4 will not serve your assets. To enable this functionality you need to go into config/application.rb and add this line:
config.serve_static_assets = true
Have a read through this documentation on heroku as well - https://devcenter.heroku.com/articles/rails-4-asset-pipeline
Hope it helps. :)
Rails 4
The problem is a common issue with the Hartl tutorial - it derives from using Rails 3 in the tutorial, and a later version being used widely now
I tried looking for references on this, but I couldn't. I've found them somewhere before - will have another look for you.
Anyway, in Rails 4, need this (we have this in our Rails 4 apps):
#config/environments/development.rb
Rails.application.configure do
This sets the configure code block for the correct object. I think Rails changed some of its core functionality in 4.0+, which is why you're getting the issue now
Related
I am getting the error when starting the server rails s in my local environment.
I tried to google , but all these capistrano Dont know how to build tasks are all deploy related, not when starting server in local environment.
I am not sure either whether its a rails or capistrano issue.
Here is the link of the trace. Gist.
Any help is appreciated!
application.rb
You probably have Capistrano-related gems in your Gemfile but have not marked them as require: false. As a result, when Rails boots up, it tries to load all of that Capistrano code, which is not how Capistrano is intended to be used.
In your case it looks like the capistrano-gitflow gem is the culprit. Always use require: false for it and all other Capistrano-related gems in the Gemfile, like this:
gem "capistrano", "~> 3.10", require: false
gem "capistrano-bundler", require: false
gem "capistrano-rails", require: false
The fact that this is not explained in the Capistrano documentation is an oversight that I will try to get corrected.
I am deployed my rails project to the AWS. I have following in my Gemfile:
group :development do
gem 'capistrano'
gem 'capistrano3-puma'
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-bundler', require: false
gem 'capistrano-rvm'
end
In my production.rb
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = true
config.assets.digest = true
However, when I load my application in the web browser I see in the console that my application-xxxxxx.css and application-xxxxxx.js gives 404 not found error. Also, when I go to the server and look for the file in public/assets/ folder, the application-xxxxxx.js is present there.
Can anyone help me with this?
The problem was not in the asset compilation and deployment. I had to change the path from root /home/deploy/portal/public; to /home/deploy/portal/current/public; in nginx configuration file /etc/nginx/sites-enabled/default.
For example:
In my Gemfile there are two gems:
gem 'spreadsheet', require: false
gem 'stripe', require: false
I use 'spreadsheet' in rake tasks and it's clear that require: false makes better performance.
But my rails app also uses 'stripe' for payment in app folder(models,controllers..etc) which is not often executed. (On production server, with config.eager_load = true )
Will the performance be better to set require: false for gem 'stripe' ?
I've read straight through this question but can't get clear answer: Bundler: What does :require => false in a Gemfile mean?
You'll get some improvements in application start-up time - gems that have require: false are not loaded when application starts. This can also help in test mode - see https://www.andywaite.com/2015/08/15/faster-tdd-in-rails-with-bundlers-require-false.html. Also, if you only need those gems in rake tasks, or one-off scripts, the main application will use less memory, which is always a nice bonus.
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
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.