Skip to content

Commit

Permalink
Rather than the exception MissingTranslationFieldError just output a …
Browse files Browse the repository at this point in the history
…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
parndt committed Feb 27, 2012
1 parent a4e0b27 commit 76767e8
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/friendly_id/globalize.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 76767e8

Please sign in to comment.