globalize/globalize

ArgumentError (wrong number of arguments (given 1, expected 0)) in Rails 6.1.2 and ruby 3.0.0

adriacarro opened this issue ยท 8 comments

I'm getting ArgumentError (wrong number of arguments (given 1, expected 0)) when I create new records from nested models.
No errors

Category.create(store_id: Store.first.id)

ArgumentError (wrong number of arguments (given 1, expected 0)) error

Store.first.categories.create

category.rb

class Category < ApplicationRecord
  belongs_to :store
  translates :name
  globalize_accessors locales: I18n.available_locales, attributes: %i[name]
end

We are using following versions:

  • globalize 6.0.0
  • globalize-accessors 0.3.0
  • rails 6.1.2.1
  • ruby 3.0.0

@adriacarro Did you find any solution for this, I keep getting the same issue when using it with a devise model

Same issue as #774

My fix is to create a monkey-patch in lib/core_extensions/globalize/active_record/instance_methods.rb :

module Globalize
  module ActiveRecord
    module InstanceMethods
      def save(**)
        result = Globalize.with_locale(translation.locale || I18n.default_locale) do
          without_fallbacks do
            super
          end
        end

        globalize.clear_dirty if result

        result
      end
    end
  end
end

And load it at boot

require 'core_extensions/globalize/active_record/instance_methods'
Globalize.include Globalize::ActiveRecord::InstanceMethods

I ran into the same issue but with Rails 6.0.3.5.

I tried to fix it with def save(*, **), but now I get:

  9) API::V1::Hints GET root returns all hints
     Failure/Error: super

     ActiveRecord::StatementInvalid:
       PG::SyntaxError: ERROR:  zero-length delimited identifier at or near """"
       LINE 1: ..., "content" = $2 WHERE "preparation_translations"."" IS NULL
                                                                    ^
     # ./lib/core_extensions/globalize/active_record/instance_methods.rb:7:in `block (2 levels) in save'
     # ./lib/core_extensions/globalize/active_record/instance_methods.rb:6:in `block in save'
     # ./lib/core_extensions/globalize/active_record/instance_methods.rb:5:in `save'
     # ./spec/api/hints_spec.rb:4:in `block (2 levels) in <main>'
     # ./spec/api/hints_spec.rb:7:in `block (2 levels) in <main>'
     # ------------------
     # --- Caused by: ---
     # PG::SyntaxError:
     #   ERROR:  zero-length delimited identifier at or near """"
     #   LINE 1: ..., "content" = $2 WHERE "preparation_translations"."" IS NULL
     #                                                                ^
     #   ./lib/core_extensions/globalize/active_record/instance_methods.rb:7:in `block (2 levels) in save'

I am lost and have trouble upgrading my customers' rails project to rails 6.0

This worked for me ๐Ÿ‘๐Ÿผ

# config/initializers/globalize.rb

Rails.application.reloader.to_prepare do
  Globalize::ActiveRecord::InstanceMethods.module_eval do
    def save(**)
      result = Globalize.with_locale(translation.locale || I18n.default_locale) do
        without_fallbacks do
          super
        end
      end

      globalize.clear_dirty if result

      result
    end
  end
end

Thanks.
That worked for me too.

Anyone keen to open a pull request with a solution for Globalize? ๐Ÿฅฐ

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This should have been fixed by #778