{"id":2161,"date":"2013-02-19T10:01:39","date_gmt":"2013-02-19T01:01:39","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=2161"},"modified":"2018-11-14T16:33:56","modified_gmt":"2018-11-14T07:33:56","slug":"%e3%83%ab%e3%83%bc%e3%83%ab%e3%82%92%e4%bb%95%e7%b5%84%e3%81%bf%e3%81%ab%e7%bd%ae%e3%81%8d%e6%8f%9b%e3%81%88%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/02\/19\/%e3%83%ab%e3%83%bc%e3%83%ab%e3%82%92%e4%bb%95%e7%b5%84%e3%81%bf%e3%81%ab%e7%bd%ae%e3%81%8d%e6%8f%9b%e3%81%88%e3%82%8b\/","title":{"rendered":"\u30eb\u30fc\u30eb\u3092\u4ed5\u7d44\u307f\u306b\u7f6e\u304d\u63db\u3048\u308b"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>Rails \u306b\u9650\u3063\u305f\u8a71\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u5927\u304d\u304f\u306a\u308b\u306b\u5f93\u3044\u300c\u25cb\u25cb\u3059\u308b\u3068\u304d\u306f\u5fc5\u305a\u25cb\u25cb\u3059\u308b\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u306f\u5897\u3048\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u826f\u3044\u30eb\u30fc\u30eb\u306f\u898f\u5f8b\u3092\u3082\u305f\u3089\u3057\u307e\u3059\u304c\u3001\u305d\u3046\u3067\u3082\u306a\u3044\u30eb\u30fc\u30eb\u306f\u3042\u307e\u308a\u30e1\u30ea\u30c3\u30c8\u3082\u306a\u304f\u3001\u6570\u304c\u5897\u3048\u3066\u304f\u308b\u3068\u300c\u5b88\u3089\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u300d\u3068\u3044\u3046\u91cd\u5727\u3060\u3051\u304c\u6b8b\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u300c\u5fc5\u305a\u25cb\u25cb\u3059\u308b\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb<\/h2>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:ruby decode:true\">#\r\n# \u30b7\u30b9\u30c6\u30e0\u904b\u7528\u8005\u306b\u9001\u4fe1\u3059\u308b\u30e1\u30fc\u30eb\u3092\u69cb\u7bc9\u3059\u308b.\r\n#\r\n# \u203b\u30e1\u30fc\u30eb\u306e Subject \u306f build_subject \u30e1\u30bd\u30c3\u30c9\u3092\u901a\u3057\u3066\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044.\r\n#\r\nclass SystemMailer &lt; ActionMailer::Base\r\n\r\n  # \u901a\u77e5\u30e1\u30fc\u30eb. \r\n  def notice(subject, message)\r\n    # View \u3067\u4f7f\u3044\u307e\u3059. \r\n    @message = message\r\n\r\n    mail :from    =&gt; 'noreply@example.com',\r\n         :to      =&gt; 'you@example.com',\r\n         :subject =&gt; build_subject(\"[NOTICE] #{subject}\") # \u5fc5\u305a build_subject \u3092\u547c\u3076.\r\n  end \r\n\r\n  # \u30a8\u30e9\u30fc\u30e1\u30fc\u30eb. \r\n  def error(subject, message)\r\n    # View \u3067\u4f7f\u3044\u307e\u3059. \r\n    @message = message\r\n\r\n    mail :from    =&gt; 'noreply@example.com',\r\n         :to      =&gt; 'you@example.com',\r\n         :subject =&gt; build_subject(\"[ERROR] #{subject}\") # \u5fc5\u305a build_subject \u3092\u547c\u3076.\r\n  end \r\n\r\n  protected\r\n\r\n  # \u30e1\u30fc\u30eb\u306e Subject \u3092\u69cb\u7bc9\u3059\u308b. \r\n  # \u4e0e\u3048\u3089\u308c\u305f\u6587\u5b57\u5217\u306b Rails.env \u3068\u30b5\u30fc\u30d0\u540d\u3092\u4ed8\u52a0\u3057\u305f\u6587\u5b57\u5217\u3092\u751f\u6210\u3059\u308b. \r\n  # Ex. build_subject('[NOTICE] \u30d0\u30c3\u30c1\u51e6\u7406\u5b8c\u4e86') # =&gt; '[production][example.com][NOTICE] \u30d0\u30c3\u30c1\u51e6\u7406\u5b8c\u4e86' \r\n  def build_subject(subject)\r\n    \"[#{Rails.env}][#{Socket.gethostname}]#{subject}\"\r\n  end \r\n\r\nend<\/pre>\n<p>\u3053\u308c\u306f Rails \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u30b7\u30b9\u30c6\u30e0\u904b\u7528\u8005\u306b\u5bfe\u3059\u308b\u901a\u77e5\u30e1\u30fc\u30eb\u3092\u69cb\u7bc9\u3059\u308b\u30af\u30e9\u30b9\u3092\u60f3\u5b9a\u3057\u3066\u66f8\u3044\u305f\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>notice \u3068 error \u306f\u305d\u308c\u305e\u308c\u3001\u901a\u77e5\u30e1\u30fc\u30eb\u3001\u30a8\u30e9\u30fc\u30e1\u30fc\u30eb\u3092\u69cb\u7bc9\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n<p>\u6ce8\u76ee\u3057\u3066\u3044\u305f\u3060\u304d\u305f\u3044\u306e\u306f\u3001\u300c# \u5fc5\u305a build_subject \u3092\u547c\u3076.\u300d\u3068\u300c# \u203b\u30e1\u30fc\u30eb\u306e Subject \u306f build_subject \u30e1\u30bd\u30c3\u30c9\u3092\u901a\u3057\u3066\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044.\u300d\u3068\u3044\u3046\u30b3\u30e1\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<p>\u30e1\u30fc\u30eb\u306e Subject \u306f\u5fc5\u305a build_subject \u3092\u901a\u3057\u3066\u69cb\u7bc9\u3059\u308b\u30eb\u30fc\u30eb\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>build_subject \u3092\u898b\u308b\u3068\u3001\u6e21\u3055\u308c\u305f\u6587\u5b57\u5217\u306b Rails.env \u3068\u30b7\u30b9\u30c6\u30e0\u304c\u52d5\u4f5c\u3059\u308b\u30db\u30b9\u30c8\u540d\u3092\u4ed8\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30e1\u30fc\u30eb\u306e Subject \u306b Rails.env \u3068\u30db\u30b9\u30c8\u540d\u304c\u542b\u307e\u308c\u308b\u3068\u4fbf\u5229\u3060\u3002<\/li>\n<li>Rails.env \u3068\u30db\u30b9\u30c8\u540d\u3092\u4ed8\u52a0\u3059\u308b\u51e6\u7406\u3092 build_subject \u30e1\u30bd\u30c3\u30c9\u306b\u62bd\u51fa\u3057\u305f\u3002<\/li>\n<li>\u30e1\u30fc\u30eb\u306e Subject \u306f\u5fc5\u305a build_subject \u3092\u901a\u3057\u3066\u69cb\u7bc9\u3059\u308b\u3068\u3044\u3046\u30eb\u30fc\u30eb\u304c\u751f\u307e\u308c\u305f\u3002<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u7d4c\u7def\u3067\u3001\u3053\u306e\u3088\u3046\u306a\u3053\u3068\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30eb\u30fc\u30eb\u3092\u4ed5\u7d44\u307f\u306b\u7f6e\u304d\u63db\u3048\u308b<\/h2>\n<p>\u300c\u5fc5\u305a build_subject \u3092\u547c\u3076\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u306f\u59a5\u5f53\u3067\u3057\u3087\u3046\u304b\u3002\u898f\u5f8b\u3092\u3082\u305f\u3089\u3059\u826f\u3044\u30eb\u30fc\u30eb\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u5fc5\u305a\u3084\u3089\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u3042\u308b\u306a\u3089\u3001\u81ea\u52d5\u7684\u306b\u3084\u3063\u3066\u304a\u3044\u3066\u304f\u308c\u308b\u4ed5\u7d44\u307f\u304c\u3042\u3063\u305f\u65b9\u304c\u5e78\u305b\u306b\u306a\u308c\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"lang:ruby decode:true \">class SystemMailer &lt; ActionMailer::Base\r\n\r\n  # \u901a\u77e5\u30e1\u30fc\u30eb.\r\n  def notice(subject, message)\r\n    # View \u3067\u4f7f\u3044\u307e\u3059.\r\n    @message = message\r\n\r\n    mail :from    =&gt; 'noreply@example.com',\r\n         :to      =&gt; 'you@example.com',\r\n         :subject =&gt; \"[NOTICE] #{subject}\"\r\n  end\r\n\r\n  # \u30a8\u30e9\u30fc\u30e1\u30fc\u30eb.\r\n  def error(message)\r\n    # View \u3067\u4f7f\u3044\u307e\u3059.\r\n    @message = message\r\n\r\n    mail :from    =&gt; 'noreply@example.com',\r\n         :to      =&gt; 'you@example.com',\r\n         :subject =&gt; \"[ERROR] #{subject}\"\r\n  end\r\n\r\n  protected\r\n\r\n  # Subject \u306b Rails.env \u3068\u30db\u30b9\u30c8\u540d\u3092\u4ed8\u52a0\u3059\u308b.\r\n  def mail_with_subject_prefix(headers={}, &amp;block)\r\n    mail = mail_without_subject_prefix(headers, &amp;block)\r\n    mail.subject = \"[#{Rails.env}][#{Socket.gethostname}]#{mail.subject}\"\r\n    mail\r\n  end\r\n  alias_method_chain :mail, :subject_prefix\r\n\r\nend<\/pre>\n<p>mail_with_subject_prefix \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u6210\u3057\u3001alias_method_chain \u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u306e mail \u30e1\u30bd\u30c3\u30c9\u3092\u7f6e\u304d\u63db\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>\u300c\u5fc5\u305a build_subject \u3092\u547c\u3073\u51fa\u3059\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u3092\u300cSubject \u306b\u306f\u81ea\u52d5\u7684\u306b Rails.env \u3068\u30db\u30b9\u30c8\u540d\u304c\u4ed8\u52a0\u3055\u308c\u308b\u300d\u3068\u3044\u3046\u4ed5\u7d44\u307f\u306b\u5909\u3048\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u3044\u3064\u3067\u3082\u4e0a\u624b\u304f\u3044\u304f\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u304c\u3001\u30eb\u30fc\u30eb\u3092\u4ed5\u7d44\u307f\u306b\u7f6e\u304d\u63db\u3048\u308b\u30e1\u30ea\u30c3\u30c8\u306f\u975e\u5e38\u306b\u5927\u304d\u3044\u3067\u3059\u3002<\/p>\n<p>\u4f55\u304b\u3092\u5b9f\u73fe\u3059\u308b\u65b9\u6cd5\u304c\u8907\u6570\u3042\u308b\u3068\u304d\u306f\u3001\u300c\u30eb\u30fc\u30eb\u3088\u308a\u4ed5\u7d44\u307f\u3092\u4f5c\u308b\u300d\u3068\u3044\u3046\u89b3\u70b9\u3067\u8003\u3048\u3066\u307f\u3066\u306f\u3069\u3046\u3067\u3057\u3087\u3046\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>&nbsp;<\/p>\n<p>Rails \u306b\u9650\u3063\u305f\u8a71\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u5927\u304d\u304f\u306a\u308b\u306b\u5f93\u3044\u300c\u25cb\u25cb\u3059\u308b\u3068\u304d\u306f\u5fc5\u305a\u25cb\u25cb\u3059\u308b\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u306f\u5897\u3048\u3066\u3044\u304d\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2013\/02\/19\/%e3%83%ab%e3%83%bc%e3%83%ab%e3%82%92%e4%bb%95%e7%b5%84%e3%81%bf%e3%81%ab%e7%bd%ae%e3%81%8d%e6%8f%9b%e3%81%88%e3%82%8b\/\">\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],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2161"}],"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=2161"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2161\/revisions"}],"predecessor-version":[{"id":17952,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2161\/revisions\/17952"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=2161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=2161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=2161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}