Permalink
Browse files

Rather than the exception MissingTranslationFieldError just output a …

…helpful message to the user when the required column is missing. Rationale here is that you can't even run rake db:migrate to add the column if the exception is being raised.
  • Loading branch information...
1 parent a4e0b27 commit 76767e8a1175a6da4e01d5877158edc11133ef7d @parndt parndt committed Feb 27, 2012
Showing with 2 additions and 5 deletions.
  1. +2 −5 lib/friendly_id/globalize.rb
@@ -50,9 +50,6 @@ class Post < ActiveRecord::Base
=end
module Globalize
- class MissingTranslationFieldError < StandardError
- end
-
def self.included(model_class)
model_class.instance_eval do
friendly_id_config.use :slugged
@@ -61,10 +58,10 @@ def self.included(model_class)
# Check if slug field is enabled to be translated with Globalize
if table_exists?
if columns.map(&:name).exclude?(friendly_id_config.query_field)
- raise MissingTranslationFieldError.new("Missing field '#{friendly_id_config.query_field}' in db table")
+ puts "\n[FriendlyId] Missing field '#{friendly_id_config.query_field}' in DB table '#{table_name}'. This is required for FriendlyId to properly function with the :globalize option.\n\n"
end
unless respond_to?('translated_attribute_names') || translated_attribute_names.exclude?(friendly_id_config.query_field.to_sym)
- raise MissingTranslationFieldError.new("You need to translate '#{friendly_id_config.query_field}' field with Globalize (add 'translates :#{friendly_id_config.query_field}' in your model)")
+ puts "\n[FriendlyId] You need to translate '#{friendly_id_config.query_field}' field with Globalize (add 'translates :#{friendly_id_config.query_field}' in your model '#{self.class.name}')\n\n"
end
end
end

0 comments on commit 76767e8

Please sign in to comment.