globalize / globalize-accessors

Easily access (read and write) globalize translated fields without fiddling with locale
Other
110 stars 43 forks source link

Wrong number of arguments (3 for 2) #29

Closed mareczek closed 8 years ago

mareczek commented 8 years ago

Whenever I send params, such as:

{
  name_en: "English name"
  name_de: "German name"
}

and in the controller:

@model.update_attributes(params)

i get: ArgumentError (wrong number of arguments (3 for 2)):

globalize-accessors is at version 0.2.1

mareczek commented 8 years ago

The problem occurs when used with gem enumerize

abuisman commented 8 years ago

@mareczek I have just gotten the same error. I have not yet investigated what I need to do to fix it though. Have you found a solution/cause?

mareczek commented 8 years ago

I did not solve the problem. Both enumerize and globalize overwrite the same method, hence the problem.

My temp solution working until now was to not use both gems together in the same model.

abuisman commented 8 years ago

Morgoth came to me in a vision and helped me produce this workaround:

  def write_attribute(name, value, options = {})
    return Globalize::ActiveRecord::InstanceMethods.instance_method(:write_attribute).bind(self).call(name, value, options) if translated?(name)
    super(name, value)
  end

You can put this in the class that has both enumerize and globalize.

Update:

Make sure that you extend Enumerize after the translates though!

class MyModel < ActiveRecord::Base
   translates :name

   extend Enumerize

   def write_attribute...
end
shioyama commented 8 years ago

Hmm.. I don't seem to be able to reproduce this. I can update attributes fine with both globalize (latest on master branch) and enumerize (2.0.0). Can either of you provide a concrete example?

shioyama commented 8 years ago

This has been fixed in brainspec/enumerize#236, closing.