1

After an upgrade to RoR 3.4.2/8.0.2, migrating the db hits the following problem.

When running rake db:migrate, I see the following error:

... == 20151121064619 AddUploadToEntries: migrating =============================== -- add_attachment(:entries, :upload) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: (StandardError) wrong number of arguments (given 4, expected 3) /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:338:in 'add_column' /usr/local/bundle/gems/paperclip-6.1.0/lib/paperclip/schema.rb:27:in 'block (2 levels) in Paperclip::Schema::Statements#add_attachment' ... 

The affected rb looks like this:

class AddUploadToEntries < ActiveRecord::Migration[8.0] def self.up add_attachment :entries, :upload end def self.down remove_attachment :entries, :upload end end 

However, the error message doesn't look correct because the "complaining" call appears to expect four arguments - not three as per the error message:

def add_column(table_name, column_name, type, **options) 

... as in /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:338

def add_column(table_name, column_name, type, **options) # :nodoc: type = type.to_sym if invalid_alter_table_type?(type, options) alter_table(table_name) do |definition| definition.column(column_name, type, **options) end else super end end 

The "offending" call sends four arguments too as is correctly reported in the error message:

 ... add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options) ... 

... as in /usr/local/bundle/gems/paperclip-6.1.0/lib/paperclip/schema.rb:27

def add_attachment(table_name, *attachment_names) raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration." if attachment_names.empty? options = attachment_names.extract_options! attachment_names.each do |attachment_name| COLUMNS.each_pair do |column_name, column_type| column_options = options.merge(options[column_name.to_sym] || {}) add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options) end end end 

So there is does not seem to be any arguments' number mismatch. I should be missing something here, surely. Can anybody help, please?

1 Answer 1

1

"...the "complaining" call appears to expect four arguments - not three as per the error message:"

def add_column(table_name, column_name, type, **options) 

The call actually expects 3 arguments table_name, column_name, type, and then an open ended list of keyword arguments **options.

In the invocation:

add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options) 

column_options is a Hash or a 4th argument.

You can easily recreate the issue:

def example(arg, **rest); end example('a', {b: 1}) #=> wrong number of arguments (given 2, expected 1) (ArgumentError) 

While you could get around this specific issue by patching the gem to pass the column_options appropriately, e.g. **column_options, the paperclip gem has not been maintained for years and is likely to have numerous other issues with Ruby > 2.7 or rails > 7.1 because of the syntax changes in ruby 3. (More about that Here)

Your best bet is to move to something like ActiveStorage and paperclip even provides a MIGRATION GUIDE

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.