Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TranslationKey < ActiveRecord::Base
- has_many :key_values
- has_many :translation_values, :through => :key_values
- belongs_to :client
- validates_uniqueness_of :name, :scope => [:client_id], :message => "already exist in another key"
- after_destroy { |record| logger.info( "key #{record.id} was destroyed." ) }
- end
- class KeyValue < ActiveRecord::Base
- belongs_to :translation_value
- belongs_to :translation_key
- belongs_to :environment
- after_save { logger.info( 'key_value saved!' ) }
- end
- #translation_keys controller
- def destroy
- @key = TranslationKey.find(params[:id])
- @key.destroy
- destroy_key_values
- respond_to do |format|
- flash[:notice] = 'Key was deleted.'
- format.html { redirect_to(translation_keys_path) }
- format.xml { head :ok }
- end
- end
- def destroy_key_values
- #destroy all key_value rows that relate to this key but keep the values
- @key.translation_values.each do |value|
- key_value = KeyValue.find_by_translation_key_id_and_translation_value_id(@key.id, value)
- key_value.delete
- end
- end
Add Comment
Please, Sign In to add comment