Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activerecord problem on Rails 7 - wrong number of arguments (given 2, expected 1) (ArgumentError) #133

Open
saten opened this issue Feb 2, 2024 · 0 comments

Comments

@saten
Copy link

saten commented Feb 2, 2024

Can't save a model after attaching a file to it

After adding an attachment to a model, and setting a file it can't be saved.
Saving the model works fine unless the attachment is set or modified

To Reproduce
Create a model like this on rails 7.0.8

class Core::CoreXls < ApplicationRecord
self.table_name= 'core_xlses'

#attr_accessor :excel_file_name,:excel_file_size,:excel_updated_at,:excel_created_at
has_attached_file :excel,
:url => ":s3_eu_url",
:path => "system/:class/:attachment/:id/:style/:basename.:extension",
:storage => :s3,
:bucket=>S3_CONFIG[::Rails.env]["bucket"],
:s3_protocol=>"https",
:s3_credentials => {
:access_key_id => S3_CONFIG[::Rails.env]["access_key_id"],
:secret_access_key => S3_CONFIG[::Rails.env]["secret_access_key"]
}
do_not_validate_attachment_file_type :excel
end

In a console:
c= Core::CoreXls.new
c.excel = File.open '/path/to/file'
c.save

Expected behavior
Model is saved and attachment uploaded to s3

Actual behavior
An exception is raised
/Users/saten/.rvm/gems/ruby-3.2.2/gems/activerecord-7.0.8/lib/active_record/relation.rb:464:in `update_all': wrong number of arguments (given 2, expected 1) (ArgumentError)

Additional context
It seems like update_all is being called in a pre Rails 3 way like Model.update_all(modifications_hash,finder_hash) as opposed to Model.where(finder_hash).update_all(modifications_hash)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant