Guest User

Untitled

a guest
May 26th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class TranslationKey < ActiveRecord::Base
  2. has_many :key_values
  3. has_many :translation_values, :through => :key_values
  4. belongs_to :client
  5. validates_uniqueness_of :name, :scope => [:client_id], :message => "already exist in another key"
  6.  
  7. after_destroy { |record| logger.info( "key #{record.id} was destroyed." ) }
  8. end
  9.  
  10. class KeyValue < ActiveRecord::Base
  11. belongs_to :translation_value
  12. belongs_to :translation_key
  13. belongs_to :environment
  14. after_save { logger.info( 'key_value saved!' ) }
  15. end
  16.  
  17. #translation_keys controller
  18.  
  19. def destroy
  20. @key = TranslationKey.find(params[:id])
  21. @key.destroy
  22.  
  23. destroy_key_values
  24.  
  25. respond_to do |format|
  26. flash[:notice] = 'Key was deleted.'
  27. format.html { redirect_to(translation_keys_path) }
  28. format.xml { head :ok }
  29. end
  30. end
  31.  
  32. def destroy_key_values
  33. #destroy all key_value rows that relate to this key but keep the values
  34. @key.translation_values.each do |value|
  35. key_value = KeyValue.find_by_translation_key_id_and_translation_value_id(@key.id, value)
  36. key_value.delete
  37. end
  38. end
Add Comment
Please, Sign In to add comment