Skip to content

Commit f979676

Browse files
committed
improve task - report not present records
1 parent 3f025b1 commit f979676

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/tasks/translations.rake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,17 @@ namespace :translations do
151151
attribute = row["attribute"]
152152
value = row["value"]
153153

154-
translation = model_name.translation_class.find_or_initialize_by(
154+
translation = model_name.translation_class.find_by(
155155
"#{model_name.model_name.singular}_id": model_id,
156156
locale: locale
157157
)
158158

159+
# fallback translation should be there (create_fallback task), so this is edge case meaning that probably record does not exist
160+
if translation.nil?
161+
puts "Translation not found for #{model_name.name} with ID #{model_id} and locale #{locale}."
162+
next
163+
end
164+
159165
translation[attribute] = value
160166
translation.save!
161167
end

0 commit comments

Comments
 (0)