Where does the call to the isolation_level come from?
My module fails at a.save!
module AppsHelpers
def self.create_app!
a = App.new
a.save!
a
end
end
The specific NoMethodError:
Failure/Error: #app = AppsHelpers::create_app!
NoMethodError:
undefined method `isolation_level' for ActiveRecord::Base:Class
What could possibly cause this failure?
System:
ruby 1.9.3p448
Rails 3.2.8
This was simple. I was calling a method defined in the Transactional Isolation gem: The stacktrace was not helpful because I was calling it from an installed gem and this was a missing dependency.
Related
Say I have:
app/models/food/fruit.rb:
module Food
class Fruit
class_attribute :field_mapping
self.field_mapping = MyOrg::Trees::Details.field_mapping
# other things including:
end
end
In local/development mode, I can open a console and do/get this:
rails console
[1] pry(main)> Food::Fruit
NameError: uninitialized constant MyOrg::Trees::Details
MyOrg::Trees::Details will eventually be defined via a gem, but until then I want to fake it by adding the following to the top of the same file; why isn't this doing the trick?
module MyOrg
module Trees
class Details
def field_mapping
end
end
end
end
Note: when I paste the above into a local/development console, I can then successfully do this:
[2] pry(main)> MyOrg::Trees::Details.new.field_mapping
=> nil
When I added the above fake, I accidentally started trying to reference it to test what I was doing...
rails console
[1] pry(main)> MyOrg::Trees::Details
NameError: uninitialized constant MyOrg::Trees::Details
...but I should have called Food::Fruit as before, and I would have isolated the issue...
rails console
[1] pry(main)> Food::Fruit
NoMethodError: undefined method `field_mapping' for MyOrg::Trees::Details:Class
...ah, I need to make it a class method...
module MyOrg
module Trees
class Details
def self.field_mapping
end
end
end
end
...and then...
rails console
[1] pry(main)> Food::Fruit
NoMethodError: undefined method `values' for nil:NilClass
So, I appeased the undefined method error, and now have a new problem, which is that further down the original code there is actually another reference to field_mapping (field_mapping.values) which now has to be appeased...
module MyOrg
module Trees
class Details
def self.field_mapping
{}
end
end
end
end
...and now...
rails console
[1] pry(main)> Food::Fruit
=> Food::Fruit
I'm running into this error when upgrading from Rails 6.0.3 to 6.1:
NoMethodError:
undefined method `assert_nothing_raised' for #<RSpec::ExampleGroups::EmailJob:0x00005572d8a00758>
Did you mean? assert_raises
This happens every time a test calls perform_enqueued_jobs.
I'm using RSpec 3.9.
Apparently assert_nothing_raised is a helper method defined by ActiveSupport. I was able to solve this issue by explicitly including the helper in spec/rails_helper.rb:
RSpec.configure do |config|
config.include(ActiveSupport::Testing::Assertions)
# ...
While migrating from mina 0.3.8 to 1.2.3 the below code is giving error as
NoMethodError: undefined method `isolate' for main:Object
RUBY version - 2.6.2
task :deploy_all do
isolate do
domains.each do |domain|
set :domain, domain
invoke :deploy
run!
end
end
end
I have checked the source code, could not find isolate method which is available on 0.3.8.
Any suggestion on how to fix the issue ?
I have a Rails application, recently I changed my database from MySql to PostgreSql, from then onwards active-records import method :on_duplicate_key_update is throwing an error.
def import_of_products(import_links)
Product.import import_links, :on_duplicate_key_update => [:ad_id]
end
The error showing is,
NoMethodError: undefined method `sql_for_on_duplicate_key_update' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0xab19f90>
from /home/mysystem/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-import-0.4.1/lib/activerecord-import/adapters/abstract_adapter.rb:48:in `post_sql_statements'
I'm running:
Rails version: 4.0.2
Ruby version: 2.0.0p643
I am using Kaminari 0.16.3 with Rails 4.2.0. Not sure what is going wrong, I have pasted code run by me in console, which proves kaminari gem is loaded but page method is undefined on ActiveRecord model.
abhishek#abhishek ~/my_app (master●●)$ rails c [ruby-2.1.5p273]
Loading development environment (Rails 4.2.0)
irb(main):001:0> Kaminari
=> Kaminari
irb(main):002:0> User.page
NoMethodError: undefined method `page' for User (call 'User.connection' to establish a connection):Class
Please note: I am intentionally calling page without any arguments to reproduce the issue.
Due to an issue with will_paginate and rails_admin I had this in my codebase causing the page method to be renamed to per_page_kaminari.
I have realized this late and fixed.
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
Have a look at this tutorial https://github.com/amatsuda/kaminari
This is how it works
User.page(page_number).per(records_per_page)