{"id":1328,"date":"2012-12-25T23:00:33","date_gmt":"2012-12-25T14:00:33","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=1328"},"modified":"2018-11-14T16:33:57","modified_gmt":"2018-11-14T07:33:57","slug":"%e3%83%a1%e3%82%bf%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%81%a7%e5%90%8c%e3%81%98%e5%bd%a2%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%83%83%e3%82%b5%e3%82%92%e3%81%be%e3%81%a8","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2012\/12\/25\/%e3%83%a1%e3%82%bf%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%81%a7%e5%90%8c%e3%81%98%e5%bd%a2%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%83%83%e3%82%b5%e3%82%92%e3%81%be%e3%81%a8\/","title":{"rendered":"\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u540c\u3058\u5f62\u306e\u30a2\u30af\u30bb\u30c3\u30b5\u3092\u307e\u3068\u3081\u308b"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u7df4\u7fd2\u3068\u3057\u3066\u3001\u540c\u3058\u30d1\u30bf\u30fc\u30f3\u3092\u6301\u3064\u30b3\u30fc\u30c9\u3092\u6539\u826f\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6700\u521d\u306e\u30b3\u30fc\u30c9<\/h2>\n<p>\u4f55\u304b\u306e\u4f1a\u54e1\u30b5\u30a4\u30c8\u3092\u4f5c\u3063\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u4f1a\u54e1\u30af\u30e9\u30b9\u304c\u5fc5\u8981\u3068\u306a\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a Member \u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:ruby decode:true\"># \u4f55\u304b\u306e\u4f1a\u54e1\u30b5\u30a4\u30c8\u306e\u4f1a\u54e1\u3068\u3057\u307e\u3059.\r\nclass Member &lt; ActiveRecord::Base\r\n\r\n  attr_accessible :media, :occupation\r\n\r\n  # \u3053\u306e\u30b5\u30a4\u30c8\u3092\u521d\u3081\u3066\u77e5\u3063\u305f\u30e1\u30c7\u30a3\u30a2.\r\n\u00a0 MEDIA = {\r\n\u00a0\u00a0\u00a0 1 =&gt; '\u65b0\u805e',\r\n\u00a0\u00a0\u00a0 2 =&gt; '\u30c6\u30ec\u30d3',\r\n\u00a0\u00a0\u00a0 3 =&gt; '\u9031\u520a\u8a8c',\r\n\u00a0\u00a0\u00a0 ...\r\n\u00a0 }\r\n\r\n  # \u4f1a\u54e1\u306e\u8077\u696d.\r\n\u00a0 OCCUPATION = {\r\n\u00a0\u00a0\u00a0 1 =&gt; '\u516c\u52d9\u54e1',\r\n\u00a0\u00a0\u00a0 2 =&gt; '\u4f1a\u793e\u54e1',\r\n\u00a0\u00a0\u00a0 3 =&gt; '\u4e3b\u5a66',\r\n\u00a0\u00a0\u00a0 ...\r\n\u00a0 }\r\n\r\n  # \u3053\u306e\u30b5\u30a4\u30c8\u3092\u521d\u3081\u3066\u77e5\u3063\u305f\u30e1\u30c7\u30a3\u30a2\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059.\r\n\u00a0 def media_label\r\n\u00a0\u00a0\u00a0 MEDIA[self.media]\r\n\u00a0 end\r\n\r\n  # \u4f1a\u54e1\u306e\u8077\u696d\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059.\r\n\u00a0 def occupation_label\r\n\u00a0\u00a0\u00a0 OCCUPATION[self.occupation]\r\n\u00a0 end\r\n\r\nend<\/pre>\n<p>\u4f1a\u54e1\u306e\u60c5\u5831\u3068\u3057\u3066\u306f\u3001\u300c\u3053\u306e\u30b5\u30a4\u30c8\u3092\u521d\u3081\u3066\u77e5\u3063\u305f\u30e1\u30c7\u30a3\u30a2\u300d\u3068\u300c\u4f1a\u54e1\u306e\u8077\u696d\u300d\u3092\u6301\u3061\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u306f\u6570\u5024\u3067\u4fdd\u5b58\u3057\u305f\u3044\u306e\u3067\u3001\u305d\u308c\u305e\u308c MEDIA \u3068 OCCUPATION \u3068\u3044\u3046\u5b9a\u6570\u306b\u3001\u6570\u5024\u3068\u6587\u5b57\u5217\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u3092\u4fdd\u6301\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u753b\u9762\u306a\u3069\u306b\u306f\u6570\u5024\u3067\u306f\u306a\u304f\u6587\u5b57\u5217\u3067\u8868\u793a\u3057\u305f\u3044\u306e\u3067\u3001media_label \u3068 occupation_label \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u52d5\u4f5c\u3092\u78ba\u8a8d\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:ruby decode:true\">user = User.new(:media =&gt; 3, :occupation =&gt; 1)\r\nuser.media_label      # =&gt; \"\u9031\u520a\u8a8c\"\r\nuser.occupation_label # =&gt; \"\u4e3b\u5a66\"<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u540c\u3058\u30d1\u30bf\u30fc\u30f3\u306e\u90e8\u5206\u3092\u307e\u3068\u3081\u308b<\/h2>\n<p>\u6700\u521d\u306e\u30b3\u30fc\u30c9\u3092\u773a\u3081\u3066\u3044\u308b\u3068\u3001\u540c\u3058\u30d1\u30bf\u30fc\u30f3\u306e\u90e8\u5206\u304c\u3042\u308b\u3053\u3068\u306b\u6c17\u4ed8\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u90e8\u5206\u304c\u305d\u3046\u3067\u3059\u3002<\/p>\n<pre>  # \u3053\u306e\u30b5\u30a4\u30c8\u3092\u521d\u3081\u3066\u77e5\u3063\u305f\u30e1\u30c7\u30a3\u30a2\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059.\r\n\u00a0 def media_label\r\n\u00a0\u00a0\u00a0 MEDIA[self.media]\r\n\u00a0 end\r\n\r\n  # \u4f1a\u54e1\u306e\u8077\u696d\u3092\u6587\u5b57\u5217\u3067\u8fd4\u3059.\r\n\u00a0 def occupation_label\r\n\u00a0\u00a0\u00a0 OCCUPATION[self.occupation]\r\n\u00a0 end<\/pre>\n<p>\u5c5e\u6027\u5024\u3092\u30ad\u30fc\u3068\u3057\u3066\u3001\u5b9a\u6570\u304b\u3089\u5024\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u90e8\u5206\u3092\u307e\u3068\u3081\u308b\u305f\u3081\u306b\u3001\u6b21\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre>\u00a0 def self.attr_label_reader(name)\r\n\u00a0\u00a0\u00a0 define_method(\"#{name}_label\".downcase) do\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 self.class.const_get(name.to_s.upcase)[self.send(name)]\r\n\u00a0\u00a0\u00a0 end\r\n\u00a0 end<\/pre>\n<p>name \u306b\u306f\u5c5e\u6027\u540d\uff08:media \u3084 :occupation\uff09\u304c\u6e21\u3055\u308c\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>attr_label_reader \u306e\u4e2d\u3067\u306f\u3001define_method \u3067 name \u306b\u300c_label\u300d\u3092\u4ed8\u3051\u305f\u540d\u524d\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\uff08\u4f8b\u3048\u3070 media_label \u3084 occupation_label\uff09<\/p>\n<p>\u5b9a\u7fa9\u3057\u305f\u30e1\u30bd\u30c3\u30c9\u306e\u4e2d\u3067\u306f\u3001const_get \u3067 name \u3092\u5168\u3066\u5927\u6587\u5b57\u306b\u3057\u305f\u5b9a\u6570\u3092\u53d6\u5f97\u3057\u3001\u540d\u524d\u304c name \u306e\u5c5e\u6027\u5024\u3092\u30ad\u30fc\u3068\u3059\u308b\u5024\u3092\u53d6\u5f97\u3057\u307e\u3059\uff08\u4f8b\u3048\u3070 MEDIA[self.media] \u306e\u5024\u304c\u30e1\u30bd\u30c3\u30c9\u306e\u623b\u308a\u5024\u3068\u306a\u308a\u307e\u3059\uff09\u3002<\/p>\n<p>\u307e\u3060 attr_label_reader \u3092\u5b9a\u7fa9\u3057\u305f\u3060\u3051\u306a\u306e\u3067\u3001\u305d\u308c\u3092\u4f7f\u3046\u3088\u3046\u306b\u30b3\u30fc\u30c9\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:ruby decode:true\"># \u4f55\u304b\u306e\u4f1a\u54e1\u30b5\u30a4\u30c8\u306e\u4f1a\u54e1\u3068\u3057\u307e\u3059.\r\nclass Member &lt; ActiveRecord::Base\r\n\r\n  attr_accessible :media, :occupation\r\n\r\n  #\r\n  # \u6307\u5b9a\u3055\u308c\u305f\u5c5e\u6027\u306e\u30e9\u30d9\u30eb\u3092\u53d6\u5f97\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3059\u308b.\r\n  #\r\n  # ==== \u8a73\u7d30\r\n  # name \u306b :media \u304c\u6e21\u3055\u308c\u305f\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u5b9a\u7fa9\u3055\u308c\u308b.\r\n  #\r\n  #     def media_label\r\n  #       MEDIA[self.media]\r\n  #     end\r\n  #\r\n  # ==== \u5f15\u6570\r\n  # name:: \u5c5e\u6027\u540d.\r\n  #\r\n  def self.attr_label_reader(name)\r\n    define_method(\"#{name}_label\".downcase) do\r\n      self.class.const_get(name.to_s.upcase)[self.send(name)]\r\n    end\r\n  end\r\n\r\n  # \u3053\u306e\u30b5\u30a4\u30c8\u3092\u521d\u3081\u3066\u77e5\u3063\u305f\u30e1\u30c7\u30a3\u30a2.\r\n  MEDIA = {\r\n    1 =&gt; '\u65b0\u805e',\r\n    2 =&gt; '\u30c6\u30ec\u30d3',\r\n    3 =&gt; '\u9031\u520a\u8a8c',\r\n    ...\r\n  }\r\n\r\n  # \u4f1a\u54e1\u306e\u8077\u696d.\r\n  OCCUPATION = {\r\n    1 =&gt; '\u516c\u52d9\u54e1',\r\n    2 =&gt; '\u4f1a\u793e\u54e1',\r\n    3 =&gt; '\u4e3b\u5a66',\r\n    ...\r\n  }\r\n\r\n  attr_label_reader :media\r\n  attr_label_reader :occupation\r\n\r\nend<\/pre>\n<p>\u540c\u3058\u5f62\u3092\u3057\u3066\u3044\u305f media_label \u3068 occupation_label \u306f\u4ee5\u4e0b\u306e 2 \u884c\u306b\u7f6e\u304d\u63db\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<pre>  attr_label_reader :media\r\n  attr_label_reader :occupation<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>Rails \u306b\u306f\u304b\u3086\u3044\u3068\u3053\u308d\u306b\u624b\u304c\u5c4a\u304f\u591a\u304f\u306e\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u56fa\u6709\u306e\u300c\u304b\u3086\u3044\u3068\u3053\u308d\u300d\u306f\u5fc5\u305a\u51fa\u3066\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3046\u3044\u3063\u305f\u3068\u304d\u306b\u3001Rails\u306f\u6a5f\u80fd\u4e0d\u8db3\u3060\u3068\u5606\u304f\u306e\u3067\u306f\u306a\u304f\u3001\u304b\u3068\u3044\u3063\u3066\u540c\u3058\u30d1\u30bf\u30fc\u30f3\u306e\u30b3\u30fc\u30c9\u3092\u4e00\u751f\u61f8\u547d\u66f8\u3044\u3066\u3057\u307e\u3046\u306e\u3067\u306f\u306a\u304f\u3001\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u697d\u3092\u3059\u308b\u3079\u304d\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u7df4\u7fd2\u3068\u3057\u3066\u3001\u540c\u3058\u30d1\u30bf\u30fc\u30f3\u3092\u6301\u3064\u30b3\u30fc\u30c9\u3092\u6539\u826f\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>&nbsp;<br \/>\n\u6700\u521d\u306e\u30b3\u30fc\u30c9<br \/>\n\u4f55\u304b\u306e\u4f1a\u54e1\u30b5\u30a4\u30c8\u3092\u4f5c\u3063\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2012\/12\/25\/%e3%83%a1%e3%82%bf%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0%e3%81%a7%e5%90%8c%e3%81%98%e5%bd%a2%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%83%83%e3%82%b5%e3%82%92%e3%81%be%e3%81%a8\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[22,24,61],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1328"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=1328"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1328\/revisions"}],"predecessor-version":[{"id":17990,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1328\/revisions\/17990"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=1328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=1328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=1328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}