[logaling-commit] logaling/logaling-server [add-validation-of-language-code] Add validation of language code

Back to archive index

SUZUKI Miho null+****@clear*****
Mon Oct 8 12:46:29 JST 2012


SUZUKI Miho	2012-10-08 12:46:29 +0900 (Mon, 08 Oct 2012)

  New Revision: 1f12463153d79853fdcb681c8e6738329a9c9c14
  https://github.com/logaling/logaling-server/commit/1f12463153d79853fdcb681c8e6738329a9c9c14

  Log:
    Add validation of language code

  Modified files:
    app/models/user_glossary.rb
    app/views/user_glossaries/_form.html.haml

  Modified: app/models/user_glossary.rb (+6 -0)
===================================================================
--- app/models/user_glossary.rb    2012-10-08 12:45:45 +0900 (a1994e1)
+++ app/models/user_glossary.rb    2012-10-08 12:46:29 +0900 (3171fca)
@@ -21,6 +21,12 @@ class UserGlossary < ActiveRecord::Base
     if: "original_user_glossary_id.present?",
     on: :create
 
+  validates_each :source_language, :target_language do |record, attr, value|
+    unless ISO_639.find_by_code(value)
+      record.errors.add attr, 'には言語名コードを指定して下さい'
+    end
+  end
+
   after_create :create_personal_project!
   after_destroy :remove_personal_project!
 

  Modified: app/views/user_glossaries/_form.html.haml (+4 -0)
===================================================================
--- app/views/user_glossaries/_form.html.haml    2012-10-08 12:45:45 +0900 (f9ab62d)
+++ app/views/user_glossaries/_form.html.haml    2012-10-08 12:46:29 +0900 (bc6ac13)
@@ -22,6 +22,10 @@
     = f.label :target_language, :class => 'control-label required'
     .controls
       = f.text_field :target_language, :class => 'input-mini', :placeholder => 'ja'
+      %span.help-block
+        元言語と翻訳言語には
+        = link_to 'ISO 639', 'http://ja.wikipedia.org/wiki/ISO_639'
+        で規定されている言語の名称の略号2文字(ja や en など)を入力してください
   .control-group
     = f.label :description, :class => 'control-label'
     .controls
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Back to archive index