I am having an issue where images on my Heroku production site are not being found. I have tracked it down to the digest being different in the file system from what it is looking for in the app. For example, in the logs I see the following errors:
app[web.1]: Started GET "/assets/nfl_teams/nfcn/chi-6317d0375db3876a5057f2da59bab1dc.jpeg" for 24.55.52.101 at 2016-09-08 23:10:18 +0000
app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/nfl_teams/nfcn/chi-6317d0375db3876a5057f2da59bab1dc.jpeg"):
app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:38:in `call_app'
And when I go to the Heroku console and look up the asset using asset_path() I get the following:
$ heroku run rails console
Running rails console on ⬢ fbpm... up, run.7463
Loading production environment (Rails 4.2.5)
irb(main):001:0> puts helper.asset_path("nfl_teams/nfcn/chi.jpg")
/assets/nfl_teams/nfcn/chi-93d8c8c53ac98c60f7f3fee1fade067dfa9489b24b8fa4bb9fedd4b12da129de.jpg
=> nil
irb(main):002:0>
and finally looking at the heroku bash and checking the file in the directory I get:
$ heroku run bash
Running bash on ⬢ fbpm... up, run.7321
cd public~ $ cd public/assets/nfl_teams/nfcn
~/public/assets/nfl_teams/nfcn $ ls chi*.jpg
chi-93d8c8c53ac98c60f7f3fee1fade067dfa9489b24b8fa4bb9fedd4b12da129de.jpg
~/public/assets/nfl_teams/nfcn $
So, in the console looking at the asset path I get the following file:
/assets/nfl_teams/nfcn/chi-93d8c8c53ac98c60f7f3fee1fade067dfa9489b24b8fa4bb9fedd4b12da129de.jpg
And I get the same file when I look in the directory structure. Yet for some reason the application is looking for this file:
/assets/nfl_teams/nfcn/chi-6317d0375db3876a5057f2da59bab1dc.jpeg
Which doesn't exist and throws a routing error.
Here is my Gemfile:
source 'https://rubygems.org'
ruby '2.2.4'
#ruby-gemset=Rails_fb
gem 'rails','4.2.5'
gem 'bcrypt', '3.1.11'
gem 'annotate'
gem 'faker', '1.6.3'
gem 'select2-rails'
gem 'simple_form', '3.1.1'
gem 'cocoon'
#
# Bootstrap support gems
#
gem 'bootstrap-sass'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'font-awesome-sass', '4.6.2'
gem 'font-awesome-rails'
gem 'sass-rails', '~> 5.0.4'
#gem 'select2-sass-bootstrap-rails'
# The following Gem is used to parse the NFL page for schedules to build
# a season.
gem 'nokogiri'
# Database. Using the same database for production/development
gem 'pg'
group :development, :test do
gem 'rspec-rails', '~>3.0'
gem 'factory_girl_rails', '4.7.0'
gem 'capybara', '2.7.1'
gem 'database_cleaner'
gem 'guard-rspec', '~> 4.2'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprocess', '0.5.8'
gem 'letter_opener_web', '~>1.2.0'
end
group :test do
gem 'pry'
gem 'selenium-webdriver', '2.53.0'
gem 'libnotify', '0.9.1'
end
gem 'uglifier', '2.7.2'
gem 'coffee-rails', '4.1.1'
gem 'jquery-rails', '3.1.4'
gem 'jquery-turbolinks', '2.1.0'
gem 'turbolinks', '2.5.3'
gem 'jbuilder', '2.4.1'
group :doc do
gem 'sdoc', '0.4.1', require: false
end
group :production do
gem 'rails_12factor'
end
# To use debugger
# gem 'debugger'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
And here is the code I'm using to access the images in my views(I've tried it both with and without the asset_path() call):
<%= image_tag(asset_path(team.imagePath), size: "40") %>
Can anyone tell me why the app is looking for the wrong file? Obviously there is some disconnect in the asset pipeline but I can't figure where?
And this problem started after I upgraded from Ruby 2.0.0 to Ruby 2.2.4 which caused me to update a number of my Gems.
Hopefully this helps. In order to force a new precompile of assets on Heroku in Rails 4 you need to do the following:
rake assets:clobber
Rake assets:precompile
Then git commit/push to master and push to Heroku and it should do a new precompile that hopefully will sync up the asset pipeline. Don't use rake assets:clean as it doesn't force a new compile.
Related
I am following Ruby on Rails tutorial
and once I have pushed all my code to Github, I tried to deploy on Heroku using following commands -
$ heroku create
$ git push heroku master
$ heroku run rake db:migrate
I am getting following error
Running `rake db:migrate` attached to terminal... failed
! App not found
If I try to access my app I get Page does not exist. Following is my Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
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
I've tried some of the other solutions for the similar questions posted here, but none of them resolved my issue.
heroku run rake db:migrate --app <app-name>
heroku pg:reset DATABASE
heroku run:detached rake db:migrate
Ruby - 2.0.0
Rails - 4.0.4
OS - Mac OSX Maverick
I have installed active admin on my development machine and it works fine.
But when i run heroku run rake db:migrate it gives me following error
rake aborted! undefined method `setup' for ActiveAdmin:Module
here is my gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'pg'
gem 'haml'
gem 'haml-rails'
gem 'sorcery'#, "~> 0.7.12"
gem 'jquery-rails'
gem 'localeapp'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem "activeadmin", :git => "git://github.com/gregbell/active_admin.git"
gem 'sass-rails'#, '~> 3.2.5'
gem 'coffee-rails'#, '~> 3.2.2'
gem 'twitter-bootstrap-rails'
gem 'uglifier'
end
group :production do
gem 'thin'
end
gem "activeadmin", :git => "git://github.com/gregbell/active_admin.git"
Don't declare active admin under any group.
Atleast it wont work in production environment.
For the record, I wanted to try activeadmin-cms 0.1.0 and I had the same problem.
The gem activeadmin-cms is not compatible with activeadmin 0.6.0 (I have not tested other version of activeadmin)
.rvm/gems/ruby-1.9.3-head/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `block in setup': You have already activated rack 1.4.0,
but your Gemfile requires rack 1.2.5. Using bundle exec may solve this. (Gem::LoadError)
Is the error that I get when I try to run thin start , bundle exec thin, rails s on any of my apps. I have tried running system level and app level bundle updates/ installs, removing gemfile.lock and updating again. Sudo level installs. Nothing.
Any advice?
This is my gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.10'
gem 'rake', '0.8.7'
gem 'jquery-rails', '0.2.6'
gem 'pg', :require => 'pg'
gem 'devise'
gem 'nifty-generators'
gem 'mocha'
gem 'thin'
gem 'omniauth'
require 'oauth2'
gem 'fb_graph'
gem 'nokogiri'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'
group :development do
gem 'rspec-rails', '2.5.0'
gem 'faker', '0.9.5'
end
group :test do
gem 'rspec', '2.5.0'
gem 'webrat', '0.7.1'
gem 'spork', '0.9.0.rc5'
gem 'factory_girl_rails', '1.0'
end
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
You can try adding an .rvmrc in your project root with this content:
rvm ruby-1.9.3-head#your-project-name
After that, restart your console session. RVM will ask for permission to use the file. After that, your project will run under it's own gemspace. Run bundle again, and it will install only the required gems.
I am trying to run heroku rake db:migrate and keep running into the same problem. It says it cannot load a file --faker. I tried putting this in my gem file in every possible way. Here's my gem file right now:
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'faker', '0.3.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem 'gravatar_image_tag', '0.1.0'
gem 'will_paginate', '3.0.pre2'
group :development do
gem 'rspec-rails', '2.0.1'
gem 'annotate-models', '1.0.4'
end
group :test do
gem 'rspec', '2.0.1'
gem 'webrat', '0.7.1'
gem 'autotest-fsevent', '0.2.4'
gem 'autotest-growl', '0.2.9'
gem 'autotest', '4.3.2'
gem 'autotest-rails-pure', '4.1.0'
gem 'spork', '0.8.4'
gem 'factory_girl_rails', '1.0'
end
no matter what I do it won't load the faker file so I can complete the heroku install.
do you need to use faker on Heroku? Isn't it more for loading data during development? Did you try putting it in your development group?
Also, take a look at this post heroku rake db:migrate > no such file to load -- faker
I'm sure that I am just overlooking something simple here but this has been driving me crazy all night! When trying to deploy a Rails 3.1.rc4 application to the Cedar stack on Heroku (I did this successfully a month ago with a similar Gemfile) I am receiving this error:
Could not find sprockets-2.0.0.beta.10 in any of the sources
My Gemfile looks like this:
source 'http://rubygems.org'
# Core
gem 'rails', '3.1.0.rc4'
# Asset template engines
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-script'
gem 'uglifier'
# Misc
gem 'devise'
gem 'jquery-rails'
gem 'omniauth'
gem 'fb_graph'
gem 'compass', git: 'https://github.com/chriseppstein/compass.git', branch: 'rails31'
gem 'haml'
gem 'cancan'
gem 'kaminari'
gem 'friendly_id', '~> 3.3.0', git: 'https://github.com/norman/friendly_id.git'
gem 'recaptcha', :require => 'recaptcha/rails'
gem 'aws-ses', '~> 0.4.3', :require => 'aws/ses'
# Local Environment
group :test do
# Pretty printed test output
gem 'turn', :require => false
gem 'sqlite3'
end
# Heroku Environment
group :production do
gem 'pg'
gem 'execjs'
gem 'therubyracer'
end
After searching around and finding this article on Google Groups, I determined that this must be fixable by adding this line
gem 'sprockets', '2.0.0.beta10'
to my Gemfile and then running
bundle update sprockets
This failed with
Could not find gem 'sprockets (= 2.0.0.beta10, runtime)' in any of the gem sources listed in your Gemfile.
and at this point I don't know what to do or how to handle this. Is it possible that I need to upgrade to Rails 3.1.rc5 and if so how may I do that without starting over from scratch?
Thank you for any help that you can provide!
-Robert
Just bump your rails version up to rc5
gem 'rails', '3.1.0rc5'
then:
bundle update