Getting error after upgrading to rails 3.1.12 - ruby-on-rails-3.1

I have just upgraded from rails 3.1.11 to 3.1.12. I am using ruby 1.9.3. After I start up server using rails s, I get below error
=> Booting WEBrick
=> Rails 3.1.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Uncaught exception: No such middleware to insert after: "ActionDispatch::ShowExceptions"
My Gem file is below
source 'http://rubygems.org'
gem 'rails', '~> 3.1.12'
gem 'rake'
gem 'rack'
gem "haml"
gem "haml-rails"
gem 'mysql2'
gem 'airbrake'
gem 'newrelic_rpm'
The issue is with newrelic_rpm and airbrake gems. If both are removed the application works.
With newrelic_rpm we get this error.
Uncaught exception: undefined local variable or method `establish_connection' for ActiveRecord::Base:Class
With airbrake we get this error
Uncaught exception: No such middleware to insert after: "ActionDispatch::ShowExceptions"

Related

Requiring pry gem into ruby script causes error

I am using ruby version 2.3.3p222
Here is my Gemfile:
# Gemfile
source 'https://rubygems.org'
gem 'pry'
I run bundle and here is the resulting Gemfile.lock
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
method_source (0.9.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
PLATFORMS
ruby
DEPENDENCIES
pry
BUNDLED WITH
1.15.1
I then simply run a ruby script via ruby my_report.rb (this script is located in the same directory as Gemfile and Gemfile.lock). my_report.rb only has this in the file:
require 'pry'
Here is the error:
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/<user>/.rvm/gems/ruby-2.3.3/gems/pry-rescue-1.4.5/lib/pry-rescue.rb:15: warning: method BaseHelpers#windows? is deprecated. Use Pry:Helpers::Platform.windows? instead
/Users/<user>/.rvm/gems/ruby-2.3.3/gems/pry-stack_explorer-0.4.9.2/lib/pry-stack_explorer.rb:128:in `<top (required)>': undefined method `before_command' for #<Pry::CommandSet:0x007fccdcf0b1e8> (NoMethodError)
Question: What am I missing? How can I properly require in pry into my ruby script so that I can set breakpoints?
What eventually worked for me is I just uninstalled all of the pry versions I had installed via gem uninstall. Then: in my gemfile I specified a previous version of 0.11.3:
# Gemfile
source 'https://rubygems.org'
gem 'pry', '0.11.3'
I did bundle install and then ran my ruby script, and that worked for me.

Heroku assets are not loading and seems assets are out of date

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.

Sinatra with Kaminari: cannot load such file -- kaminari/sinatra

I want to realize pagination in Sinatra with kaminari.
My Gemfile looks like this:
source "https://rubygems.org"
gem "sinatra"
gem "activerecord", :require => "active_record"
gem "mysql2"
gem "padrino-helpers"
gem "kaminari", :require => "kaminari/sinatra"
my Sinatra config.ru has a Bundler.require.
However, Passenger displays the following error: cannot load such file -- kaminari/sinatra
I don't know what's wrong. There is not much documentation about kaminari with Sinatra, and the only bit i found was: "You need padrino-helpers and require kaminari/sinatra". And that's what i did.
Sinatra (~> 1.4.0) depends on rack (1.5.2), while kaminari (~> 0.13.0) depends on rack (~> 1.2.1). And since kaminari only began experimental support for Sinatra since version 0.13.0, there appears to be an impasse.

rake aborted! undefined method `setup' for ActiveAdmin:Module

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)

How can I use readability gem on Rails 3.0.x?

I'm going to use readability gem on my rails 3 app. I can't use it as advised on the github page http://github.com/sspinc/readability inside the app although it works fine on ruby console.
On the ruby console:
> require 'open-uri'
=> true
> require 'readability'
=> true
> doc = Nokogiri::HTML(open('http://google.com'))
=> #<Nokogiri::HTML::Document:0x81345324 name="document"
> doc.to_readable
=> #<Nokogiri::XML::Element:0x813299a8 name="html"
# (expected result without any error)
On the rails console:
> doc = Nokogiri::HTML(open('http://google.com'))
=> #<Nokogiri::HTML::Document:0x81c2baec name="document"
# (and so on.. expected result)
> readable = doc.to_readable
SyntaxError: /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:2: syntax error, unexpected '='
if(typeof console !== 'undefined') {
^
/Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:2: syntax error, unexpected '{', expecting kTHEN or ':' or '\n' or ';'
/Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/readability-0.1.5/lib/readability/js/readability.js:5: syntax error, unexpected '}', expecting $end
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
from /Users/apraditya/.rvm/gems/ruby-1.8.7-p299/gems/harmony-0.5.6/lib/harmony/page.rb:76:in `load'
I verified that it is not a javascript syntax error. Judging by the active support error, it failed loading the dependencies, I suspect that Rails has failed to load the required gems that readability use (like harmony, johnson and envjs) to handle javascript and DOM in Ruby.
So my guess was may be somthing wrong in the Gemfile? Here's my current Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'devise', '~> 1.1.5'
gem 'haml', '3.0.24'
gem 'simple_form'
gem 'cancan'
gem 'will_paginate', '~> 3.0.beta'
gem 'feedzirra', :require => [ 'feedzirra' ]
gem 'loofah', '1.0.0.beta.1'
gem 'compass', '~> 0.10.4'
gem 'meta_where', '~> 0.9'
gem 'populator'
gem 'simple-navigation'
gem 'readability'
I have tried adding :require option in readability to specify harmony, johnson and envjs; and reran 'bundle install' without any error, but I still have the same error.
I have also checked the config/application.rb to require all the gems in the Gemfile. with this line
Bundler.require(:default, Rails.env) if defined?(Bundler)
So, back to the question, how can I use readability on Rails 3.0.x? Did I miss something? I'm on MacOS 10.6.5 if that matters.
Thank you
On my Mac (Rails 3.x, Ruby 1.9.2 I had trouble with it loading the johnson gem which is a dependency . However, ruby-readability gem works.

Resources