Globalize in Rails 2: ArgumentError: wrong number of arguments (2 for 1)

19 Giu 2008
Categoria: Ruby on Rails

Sto lavorando con Globalize per rendere il mio CMS multilingua. L’installazione è andata a buon fine pur utilizzando Rails 2.0.2 (globalize non è ancora stato aggiornato a Rails 2.x).

Nel momento in cui cercavo di salvare la traduzione di uno dei campi dei miei modelli ricevevo questo fastidiosissimo errore:

ArgumentError: wrong number of arguments (2 for 1)

Questo perché in Rails 2.x il metodo attributes_with_quotes ha, a differenza di rails 1.x, due argomenti e viene ridefinito (con un argomento solo) dal plugin Globalize nel file db_translate.rb (/vendor/plugin/globalize/lib/globalize/localization/db_translate.rb)

La versione corretta funziona perfettamente (testata con 2.0.2) e ve la riporto qui sotto:

def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true)         
          if Locale.base?
            quoted = attributes.inject({}) do |quoted, (name, value)|
              if column = column_for_attribute(name)
                quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary
              end
              quoted
            end
          else
            quoted = attributes.inject({}) do |quoted, (name, value)|
              if !self.class.globalize_facets_hash.has_key?(name) &&
                column = column_for_attribute(name)
                quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary
              end
              quoted
            end
          end
          include_readonly_attributes ? quoted : remove_readonly_attributes(quoted)
        end

Se avete problemi contattatemi!
Filippo

Tag: , , ,

Lascia un Commento

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word