Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

check for paperclip fields

  • Loading branch information...
commit ae65fd19a07a95fc965a188394c234dbc5e22897 1 parent 4950854
@dalpo authored
Showing with 25 additions and 8 deletions.
  1. +25 −8 lib/has_foreign_language/i18n.rb
View
33 lib/has_foreign_language/i18n.rb
@@ -16,7 +16,7 @@ def has_foreign_language(*args)
# Define has_column? in eigenclass
eigenclass.class_eval do
define_method("has_column?") do |column|
- self.class.columns.map(&:name).include? column
+ self.columns.map(&:name).include? column.to_s
end
end
@@ -30,31 +30,48 @@ def has_foreign_language(*args)
# Define the getter
define_method(field.to_s) do
- if self.class.has_column?("#{field}_#{I18n.locale}") || self.class.has_column?("#{field}_#{I18n.locale}_file_name")
+
+ if self.class.has_column?("#{field}_#{I18n.locale}")
+ self["#{field}_#{I18n.locale}".to_sym]
+ #if paperclip field
+ elsif self.class.has_column?("#{field}_#{I18n.locale}_file_name")
self.send("#{field}_#{I18n.locale}".to_sym)
else
- super
+ self["#{field}".to_sym]
end
+
end
# Define the setter
define_method("#{field}=") do |val|
- if self.class.has_column?("#{field}_#{I18n.locale}") || self.class.has_column?("#{field}_#{I18n.locale}_file_name")
+
+ if self.class.has_column?("#{field}_#{I18n.locale}")
self["#{field}_#{I18n.locale}".to_sym] = val
+ #if paperclip field
+ elsif self.class.has_column?("#{field}_#{I18n.locale}_file_name")
+ self.send("#{field}_#{I18n.locale}".to_sym, val)
else
self[field.to_sym] = val
end
- end
-
+ end
+
# Define the getter for default_locale
define_method("#{field}_#{I18n.default_locale}") do
- self[field.to_sym]
+ if self.class.has_column?("#{field}_#{I18n.locale}_file_name")
+ self.send(field.to_sym)
+ else
+ self[field.to_sym]
+ end
end
# Define the setter for default_locale
define_method("#{field}_#{I18n.default_locale}=") do |val|
- self[field.to_sym] = val
+ if self.class.has_column?("#{field}_#{I18n.locale}_file_name")
+ self.send(field.to_sym, val)
+ else
+ self[field.to_sym] = val
+ end
end
end

0 comments on commit ae65fd1

Please sign in to comment.
Something went wrong with that request. Please try again.