ArgumentError: wrong number of arguments (0 for 1) - ruby-on-rails

I am trying to test insert a row into sqlite3 db, for the Rails Tutorial in Chapter 7. I have gone over the code many times and it looks correct, however in the console I am getting the following error. Any suggestions?
User.create(name=>"test user",:email=>"testuser#example.com",:password=>"foobar",:password_confirmation=>"foobar")
ArgumentError: wrong number of arguments (0 for 1)
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:442:in maximum'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:442:insend'
from /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:442:in maximum'
from /Users/gabemcmillan/rails_projects/sample_app/app/models/user.rb:10
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:inload'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in load_file'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:innew_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:453:in load_file'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:340:inrequire_or_load'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:491:in load_missing_constant'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:183:inconst_missing'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:181:in each'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:181:inconst_missing'
from (irb):8

It should be User.create(:name... (with a colon before name), not User.create(name...

Related

Rails Upgrade to 6.1.4.6 Active Record Exception

After upgrading the rails from "6.1.3.1" to "6.1.4.6" I started to receive a lot of errors of the same kind but in different places in a project (777 tests had errors). Not able to get error trace. The error is always the same:
ArgumentError: wrong number of arguments (given 0, expected 1)
Backend::TasksControllerTest::IndexFilterTest#test_#index_can_filter_on_lead_status:
ArgumentError: wrong number of arguments (given 0, expected 1)
app/models/campaign.rb:133:in `update_schedules'
test/controllers/backend/tasks_controller_test.rb:137:in `block in <class:IndexFilterTest>'
725) Error:
DeleteModelImportJobTest#test_removes_model_import_and_all_associated_rows:
ArgumentError: wrong number of arguments (given 0, expected 1)
app/models/office/model_import/row.rb:15:in `remove_imported_object'
app/jobs/delete_model_import_job.rb:6:in `block in perform'
app/jobs/delete_model_import_job.rb:5:in `perform'
test/jobs/delete_model_import_job_test.rb:11:in `block (2 levels) in <class:DeleteModelImportJobTest>'
test/jobs/delete_model_import_job_test.rb:10:in `block in <class:DeleteModelImportJobTest>'
726) Error:
Backend::Leads::CampaignLeadsControllerTest#test_new_includes_users_from_ponds_as_well_as_team_for_selection:
ArgumentError: wrong number of arguments (given 0, expected 1)
test/controllers/backend/leads/campaign_leads_controller_test.rb:5:in `block in <class:CampaignLeadsControllerTest>'
727) Error:
Backend::Leads::CampaignLeadsControllerTest#test_new_determines_users_without_firepoint_phone_numbers:
ArgumentError: wrong number of arguments (given 0, expected 1)
test/controllers/backend/leads/campaign_leads_controller_test.rb:5:in `block in <class:CampaignLeadsControllerTest>'
Errors Screenshot
I was trying to debug minitest tests and it seems that all related to ActiveRecord methods raising the error: delete_all!, delete, update_all, update! the transaction, etc. (see screenshots)
update! error screenshot
delete_all error screenshot
transaction error screenshot
Have no idea where to move next and how to fix it, any thoughts on how to proceed and where to look are very appreciated.
I run into same exception and what I found was defining scope as
scope :id, (id) -> { where(id: id } I had remove the scope and edit my code so everything was fine

No implicit conversion of Nil to String Error with Paperclip

In my app I've created a view which lists all the PDFs in my S3 Bucket, and for this I am using the Paperclip Gem. However I am now receiving this error in my terminal.
Error performing Courts::SyncronizeBucketJob (Job ID: 8424356c-9717-4cca-9d76-4b157bab1065) from DelayedJob(default) in 450.5ms: TypeError (no implicit conversion of nil into String):
/Users/conorquarry/RubymineProjects/pair/app/_modules/courts/models/ocr_document.rb:46:in `initialize'
/Users/conorquarry/RubymineProjects/pair/app/_modules/courts/models/ocr_document.rb:46:in `new'
/Users/conorquarry/RubymineProjects/pair/app/_modules/courts/models/ocr_document.rb:46:in `block in <class:OcrDocument>'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/interpolations.rb:35:in `block (2 levels) in interpolate'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/interpolations.rb:35:in `gsub!'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/interpolations.rb:35:in `block in interpolate'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/interpolations.rb:34:in `each'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/interpolations.rb:34:in `interpolate'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/attachment.rb:556:in `interpolate'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/attachment.rb:171:in `path'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/storage/s3.rb:355:in `block in flush_writes'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/storage/s3.rb:352:in `each'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/storage/s3.rb:352:in `flush_writes'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-6.0.0/lib/paperclip/attachment.rb:247:in `save'
/Users/conorquarry/.rvm/gems/ruby-2.5.1/gems/paperclip-meta-3.1.0/lib/paperclip-meta/attachment.rb:13:in `save'
Looking at the Paperclip Interpolation Documentation I can't see my error, does anyone have an idea of where I should start? Below is the code throwing me the error.
Paperclip.interpolates :document_folder_name do |a, _s|
Pathname.new(a.instance.object_key).dirname.to_s
end
The error is reproducible by:
Pathname.new(nil)
So in this situation, a.instance.object_key is nil.
From the interpolations doc, a.instance will be the activerecord (or whatever ORM you're using) model that's trying to generate a paperclip path that includes :document_folder_name in it.
I'd guess #object_key is a method defined on your activerecord model and is returning nil.
You can put a pry / debugger or a print statement inside that block to see what the object is, then it should be fairly easy to write a unit spec for that method to ensure it returns the correct string.
In theory calling object_key.to_s would fix the error but would mean that :document_folder_name would interpolate to an empty string when paperclip is calculating the folder path, which may not be desirable.

Why is gsub complaining about nil when my object isn't nil?

I’m using Rails 4.2.7 and have the following to trim all white space from a particular expression …
puts "division: #{division}$$"
division = division.gsub(/\A\p{Space}+|\p{Space}+\z/, '')
when I run this, eventually my program dies with this output …
division: 18-29$$
Error during processing: undefined method `gsub' for nil:NilClass
/Users/mikeb/Documents/workspace/runtrax/app/models/race_time.rb:27:in `block in <class:RaceTime>'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:448:in `instance_exec'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:448:in `block in make_lambda'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:228:in `block in halting_and_conditional'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:506:in `block in call'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:506:in `each'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:506:in `call'
/Users/mikeb/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
…
I don’t understand why gsub thinks its getting a nil when the line above, the string is clearly not empty (a value of 18-29 is printed out). Curiously, I can’t reproduce this in a Rails console, so I’m wondering it here’s something else going on or if there’s a better way to write the above.
Some thoughts:
gsub is a method on strings. test out the type for "division" with this: puts division.class you may find that while "division" is not "nil," it may not be a string so it's throwing an error. see HERE for more description.
since your code is meant to change the value of division, you can do so more elegantly and economically using a "destructive method" as follows: division.gsub!(/\A\p{Space}+|\p{Space}+\z/, '') See HERE for a discussion of destructive methods (note the "!", also called "bang"). This probably doesn't solve the original question, but it does pretty up your code.

Dir.glob with sort issue

As in "Alphabetize results of Dir.glob", I use sort to get file list in alphabetical order:
Dir.glob("#{options[:path]}/**/*.jpg", File::FNM_CASEFOLD).sort { |file|
dir, filename = file.match(/.+\/(.+)\/(.+)/).captures
# ---cut---
}
Without the sort it works good, but with it fails with error:
$ rake slides:import -- --user foo --path /bar/baz
(in /home/user/app_folder)
"baz/ - /bar/baz/DSC_4120.JPG - saved"
rake aborted!
ArgumentError: comparison of String with 0 failed
/home/footoo/footoo/lib/tasks/slides.rake:41:in `>'
/home/footoo/footoo/lib/tasks/slides.rake:41:in `sort'
/home/footoo/footoo/lib/tasks/slides.rake:41:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => slides:import
Any idea what's wrong ?
Full code available on Github.
When sort is given a block it expects it to return -1,0 or 1 in order to know how to sort (a custom <=> function). You need to add each after sort to get back the default sort and the intended behavior.
Dir.glob("#{options[:path]}/**/*.jpg", File::FNM_CASEFOLD).sort.each{|file|
....
}
Read the documentation here: http://ruby-doc.org/core-2.2.0/Array.html#method-i-sort

How to Calculate Nothing - Nil on Rails

Rails 4, Spree 2.1
The Issue:
Adding an item to cart with the Spree Flexi Variants engraving calculator, I get an error:
undefined method `value' for nil:NilClass
Is this line in my engraving calculator model causing this error?
def compute(product_customization, variant=nil)
return 0 unless valid_configuration? product_customization
# expecting only one CustomizedProductOption
opt = product_customization.customized_product_options.detect {|cpo| cpo.customizable_product_option.name == "inscription" } rescue ''
opt.value.length * (preferred_price_per_letter || 0)
end
def valid_configuration?(product_customization)
true
end
And as for the value method, any ideas on that?
I've tried defining value but nothing seems to work. I have another calculator called amount times contant. This is setup pretty much the same way; however, this one works. Getting kind of confused and way past my deadline.
Here is the github repo with the branch that I am using: https://github.com/jsqu99/spree_flexi_variants/tree/spree-2-1-wip
Trace:
NoMethodError (undefined method `value' for nil:NilClass)
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/calculator/engraving.rb:29:in `compute'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/product_customization.rb:11:in `price'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `block in add_to_line_item'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `map'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `add_to_line_item'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:7:in `add'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:36:in `attempt_cart_add'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:17:in `block in populate'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:16:in `each'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:16:in `populate'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/controllers/spree/orders_controller_decorator.rb:18:in `populate'
The source code you pointed to on github contains a different definition of compute as follows:
which is consistent with your stack trace, since line 29 of engraving.rb involves an invocation of value. I'm not familiar with spree, but based on this code, the detect call is returning nil.

Resources