I'm running rails 5, upgraded from 4.2.x
In the console and when running methods that fail, the error
doesn't show the line number, I only get to see:
Traceback (most recent call last):
NoMethodError (undefined method `[]' for nil:NilClass)
I made sure development.rb has:
config.log_level = :debug
My gemfile:
source 'https://rubygems.org'
gem 'rails', '5.1.2' # mothership
gem 'bootstrap-sass' # crutches
gem 'sass-rails' # Use SCSS for stylesheets
gem 'devise' # login/sessions
gem 'devise-i18n' # login/sessions
gem 'haml' # markup language
gem 'uglifier', '>= 1.3.0' # Use Uglifier as compressor for JavaScript assets
gem 'coffee-rails'
gem 'jquery-rails' # Use jquery as the JavaScript library
gem 'bcrypt', '~> 3.1.7' # Use ActiveModel has_secure_password
gem 'html5_validators'
gem 'execjs'
gem 'puma'
gem 'pg'
gem 'listen'
group :development do
gem 'rails_db'
gem 'hirb'
gem "better_errors"
gem "binding_of_caller"
end
group :production do
gem 'aws-sdk-rails'
gem 'rails_12factor'
end
What should I change so I get to see line where error occurs?
If you do something like this in the console:
begin
your_method_call
rescue => e
puts e.backtrace
end
You will be able to rescue the exception and print the backtrace. You don't have to puts it, you can do whatever you want with the backtrace, but you get the idea.
Hope this help.
Related
I'm trying to install fat free crm with ruby on rails on Windows 7, but when I put the command
rake db:create RAILS_ENV=production
it says
rake aborted!
LoadError: cannot load such -- 2.1/pg_ext
Normally, it would say what gem I should install, but not in this case.
How can I solve this error?
Edit:
A friend of mine suggested to uncomment mysql2 and comment pg on the Gemfile file in the proyect like this:
gem 'mysql2'
#gem 'sqlite3'
#gem 'pg'
But now I get this:
Unable to load the EventMachine C extension; To use the pure-ruby reactor, requi
re 'em/pure_ruby'
C:/Ruby21/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': ca
nnot load such file -- 2.1/rubyeventmachine (LoadError)
Have any ideas of why this happends?
Here is my Gemfile:
source 'https://rubygems.org'
# Uncomment the database that you have configured in config/database.yml
# ----------------------------------------------------------------------
gem 'mysql2'
# gem 'sqlite3'
# gem 'pg'
# Removes a gem dependency
def remove(name)
#dependencies.reject! {|d| d.name == name }
end
# Replaces an existing gem dependency (e.g. from gemspec) with an alternate source.
def gem(name, *args)
remove(name)
super
end
# Bundler no longer treats runtime dependencies as base dependencies.
# The following code restores this behaviour.
# (See https://github.com/carlhuda/bundler/issues/1041)
spec = Bundler.load_gemspec( File.expand_path("../fat_free_crm.gemspec", __FILE__) )
spec.runtime_dependencies.each do |dep|
gem dep.name, *(dep.requirement.as_list)
end
# Remove premailer auto-require
gem 'premailer', :require => false
# Remove fat_free_crm dependency, to stop it from being auto-required too early.
remove 'fat_free_crm'
group :development do
# don't load these gems in travis
unless ENV["CI"]
gem 'thin'
gem 'quiet_assets'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rvm'
#~ gem 'capistrano-chruby'
#~ gem 'capistrano-rbenv'
gem 'guard'
gem 'guard-rspec'
gem 'guard-rails'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end
end
group :development, :test do
gem 'rspec-rails', '~> 2'
gem 'headless'
gem 'debugger', :platforms => 'mri_19' unless ENV["CI"]
gem 'byebug', :platforms => ['mri_20', 'mri_21'] unless ENV["CI"]
gem 'pry-rails' unless ENV["CI"]
end
group :test do
gem 'capybara'
gem 'selenium-webdriver'
gem 'database_cleaner'
gem "acts_as_fu"
gem 'factory_girl_rails'
gem 'zeus' unless ENV["CI"]
gem 'coveralls', :require => false
gem 'timecop'
end
group :heroku do
gem 'unicorn', :platform => :ruby
gem 'rails_12factor'
end
# 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'
gem 'uglifier', '>= 1.0.3'
gem 'execjs'
gem 'therubyracer', :platform => :ruby unless ENV["CI"]
end
gem 'turbo-sprockets-rails3'
It sounds like you are missing the pg gem from your Gemfile. Is it in the development group?
Can you post your Gemfile?
Uncomment #gem pg.
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' is a separate error. Where did you get that Gemfile?
I'm following SaaS from edX and I'm trying to run my rails server that I created using
rails s
and it keeps throwing a load error for
gem/ruby-1.9.3-p448/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so:
undefined symbol: ruby_current_thread
I'm not quite sure what I can do to fix this, or what other info would be required to help me solve this. I'm sorry for such a vague post but ruby on rails is rather new to me and I'm not sure why its throwing this
ive tried
gem install rails
and i get a permissions error
*Edit 1
Gemfile The debug19 is what i was told to put in per my instructions from edX 169.1
source 'https://rubygems.org'
gem 'rails', '3.2.14'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# 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'
gem 'haml'
# To use debugger
# gem 'debugger'
group :development ,:test do
gem 'ruby-debug19' , :require => 'ruby-debug'
end
I don't know enough about your environment to give an exact answer, but you can try removing ruby-debug-base19 and ruby-debug from your Gemfile. You can also see if it's being installed by another gem by looking for references to them in your Gemfile.lock. If they are dependencies, remove the gems they depend on as well.
I upgraded to rails4 from 3.2.2 and i now get this undefined method from my rabl template that id didn't get before the upgrade.
the "tooth" paramater on procedures is a set by a getter/setter method that is stored in the postgres database as a hstore hash named properties.
Not sure what has changed in rails4 to make this happen!
Any help would be much appreciated.
ERROR:
Showing /home/action/app/views/procedures/chart.json.rabl where line #1 raised:
undefined method `scan' for {"tooth"=>""}:Hash
Extracted source (around line #1):
1 object #procedures
2 attributes :buccal, :mesial, :occlusal, :distal, :lingual
Trace of template inclusion: app/views/procedures/_procedures_table.html.erb, app/views/procedures/chart.html.erb
Procedures model (getter and setter method for :tooth)
%w[tooth buccal mesial occlusal distal lingual].each do |key|
attr_accessible key
scope "has_#{key}", lambda { |value| where("properties #> (? => ?)", key, value) }
define_method(key) do
properties && properties[key]
end
define_method("#{key}=") do |value|
self.properties = (properties || {}).merge(key => value)
end
end
Gemfile:
source 'http://rubygems.org'
gem 'rails', '4.0.0.rc2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem "paperclip", "~> 3.0"
gem 'rabl'
gem 'activerecord-postgres-hstore'
gem "bugsnag"
gem 'country_select'
gem 'bullet', group: :development
# Asset template engines
gem 'sass-rails', '~> 4.0.0.rc1'
gem 'coffee-rails', '~> 4.0.0.rc1'
gem 'uglifier', '>= 1.3.0'
gem 'twitter-bootstrap-rails'
gem 'therubyracer', :platform => :ruby
gem 'less-rails'
gem 'jquery-ui-rails'
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
# Declarative Authorization
gem 'declarative_authorization'
gem 'protected_attributes'
# Authlogic
gem 'authlogic'
gem 'simple_form', '3.0.0.rc'
group :production do
end
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
gem 'rubber'
gem 'open4'
gem 'gelf'
gem 'graylog2_exceptions', :git => 'git://github.com/wr0ngway/graylog2_exceptions.git'
gem 'graylog2-resque'
Found the answer!! Rails 4 now has native support for Hstore, which is awesome but I hadn't realised. To fix my problem i merely followed this guide below which is great to set up my model with hstore and then deleted my getter/setter methods. http://blog.remarkablelabs.com/2012/12/a-love-affair-with-postgresql-rails-4-countdown-to-2013
After running this command
compass install bootstrap
I get this message:
identical sass/styles.scss
...
identical javascripts/bootstrap-typeahead.js
NoMethodError on line ["32"] of /Users/xxx/.rvm/gems/ruby-1.9.3-p327#favy/gems/sass-rails-3.2.6/lib/sass/rails/helpers.rb: undefined method `[]' for nil:NilClass
Run with --trace to see the full backtrace
in /Users/xxx/.rvm/gems/ruby-1.9.3-p327#favy/gems/sass-rails-3.2.6/lib/sass/rails/helpers.rb
31 def resolver
32 options[:custom][:resolver]
33 end
I tried a workaround -> https://gist.github.com/castus/4044953
def resolver
if ::Rails::env == "production"
options[:custom][:resolver]
else
Resolver.new(CompassRails.context)
end
end
& still no luck :)
I have this stuff in my config/compass.rb
require 'bootstrap-sass'
And my Gemfile
source 'http://rubygems.org'
gem "paperclip"
gem 'bootstrap-sass', '~> 2.3.1.0'
gem 'compass-rails'
gem 'bootswatch-rails'
gem 'gmaps4rails'
gem 'rails', '3.2.13'
gem 'activerecord-postgresql-adapter'
gem 'devise'
gem 'sass-rails', '~> 3.2.3'
gem "haml"
gem "haml-rails"
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# 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'
You don't need "Compass" at all if you are using Rails and Bootstrap-sass. Compass is for sites not using Rails.
Here are steps to install and bootstrap-sass
Add it to Gemfile and bundle install
Rename application.css to application.css.scss
Remove all comments in application.css.scss, make it blank
Add #import bootstrap
You are done! Treat it as normal css file and use #import to do whatever you like. But no more require in comment!
I'm installing a gem called Carrier https://github.com/stanislaw/carrier/blob/master/Gemfile into a Rails 3.2.1 app. It uses Kaminari and when I did bundle install after adding gem "carrier" to my Gemfile, it showed that I was using kaminari
Using kaminari (0.13.0)
However, when I tried to rake db:migrate, I got this error
rake aborted
undefined method `paginates_per' for Carrier::Chain(Table doesn't exist):Class
Can anyone suggest a fix for this? I've copied the gemfile from the Carrier gem below and the Gemfile for my own app below that
(Carrier gem Gemfile)
source "http://rubygems.org"
gem 'require_all'
gem 'kaminari'
gem 'unread'
gem 'sugar-high'
gem 'sweetloader'
group :development, :test do
gem 'rails', '~> 3.1.0'
gem 'unicorn'
gem 'mysql2'
gem 'devise'
gem 'rake-kit'
gem 'cutter'
gem "jeweler", ">= 1.6.4"
gem "rspec-rails", '>= 2.5'
end
group :test do
gem 'capybara'
gem 'factory_girl'
gem 'spork'
gem "launchy"
gem 'shoulda'
end
Gemfile for my starter app
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'devise'
gem 'carrier'
# 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'
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 web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
Update These are the migrations it installed when I ran install:migrations
rake carrier:install:migrations
Copied migration 20120229055640_create_messages.carrier.rb from carrier
Copied migration 20120229055641_create_chains.carrier.rb from carrier
Update
I tried to reinstall it again on another git branch it this time I got a slightly different error when I ran rake db:migrate
rake aborted!
undefined method `acts_as_readable' for Carrier::Message(Table doesn't exist):Class
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
You appear to be missing some database backing for what Carrier is trying to do. From the Carrier readme, it looks like you need to run rake carrier:install:migrations before running db:migrate. Have you done that?