{"id":11371,"date":"2020-07-18T13:07:43","date_gmt":"2020-07-18T04:07:43","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=11371"},"modified":"2023-05-27T22:47:17","modified_gmt":"2023-05-27T13:47:17","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%80%8cactiontext%e3%80%8d%e3%81%ae%e3%83%aa%e3%83%83%e3%83%81%e3%83%86%e3%82%ad%e3%82%b9%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=11371","title":{"rendered":"\u3010Ruby on Rails\u3011\u300cActionText\u300d\u306e\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u3092\u4f7f\u3046"},"content":{"rendered":"<h2>has_rich_text\u3092\u4f7f\u3046<\/h2>\n<p>\u4f7f\u7528\u3057\u305f\u3044\u30e2\u30c7\u30eb\u540d\u306b\u5bfe\u3057\u3066<span style=\"color: #ff0000;\"><strong>\u300chas_rich_text\u300d<\/strong><\/span>\u3092\u5ba3\u8a00\u3057\u307e\u3059\u3002\u3053\u308c\u3060\u3051\u3067\u30e2\u30c7\u30eb\u306b\u5bfe\u3057\u3066\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u3092\u6301\u305f\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u975e\u5e38\u306b\u7c21\u5358\u3067\u3059\u3088\u306d\u3002<\/p>\n<pre class=\"lang:default decode:true\">class \u30e2\u30c7\u30eb\u540d &lt; ApplicationRecord\r\n  has_rich_text :content\r\nend<\/pre>\n<h3>\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u306e\u30e2\u30c7\u30eb\u3092\u53d6\u5f97<\/h3>\n<pre class=\"lang:default decode:true\">\u5909\u6570 = \u30e2\u30c7\u30eb\u540d.create!(content: \"&lt;p&gt;Hello,World&lt;\/p&gt;\")<\/pre>\n<h3>\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u30e2\u30c7\u30eb\u304b\u3089HTML\u3092\u53d6\u5f97<\/h3>\n<pre class=\"lang:default decode:true\">[26] pry(main)&gt; \u30e2\u30c7\u30eb\u540d.content.to_s\r\n  Rendered vendor\/bundle\/gems\/actiontext-6.0.0\/app\/views\/action_text\/content\/_layout.html.erb (Duration: 2.3ms | Allocations: 253)\r\n=&gt; \"&lt;div class=\\\"trix-content\\\"&gt;\\n  &lt;p&gt;Hello,World&lt;\/p&gt;\\n&lt;\/div&gt;\\n\"<\/pre>\n<h3>\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u30e2\u30c7\u30eb\u304b\u3089\u30d7\u30ec\u30a4\u30f3\u30c6\u30ad\u30b9\u30c8\uff08\u4eba\u9593\u304c\u8aad\u3081\u308b\u6587\u5b57\u5217\uff09\u3092\u53d6\u5f97<\/h3>\n<pre class=\"lang:default decode:true\">[28] pry(main)&gt; \u30e2\u30c7\u30eb\u540d.content.to_plain_text\r\n=&gt; \"Hello,World\"<\/pre>\n<h2>\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u3092\u753b\u9762\u3067\u4f7f\u3046\u306b\u306f\uff1f<\/h2>\n<h3>Strong Parameter\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/h3>\n<p>Strong Parameter\u306b\u4eca\u56de\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u3067\u4f7f\u7528\u3057\u3066\u3044\u308b\u30ab\u30e9\u30e0\u3067\u3042\u308b<span style=\"color: #ff0000;\"><strong>\u300ccontent\u300d<\/strong><\/span>\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">    def \u30e2\u30c7\u30eb\u540d_params\r\n      params.require(:\u30e2\u30c7\u30eb\u540d).permit(:\u30ab\u30e9\u30e0\u540d, :content)\r\n    end<\/pre>\n<h3>\u30d3\u30e5\u30fc\u5074\u3067\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u306e\u5b9a\u7fa9\u3092\u3059\u308b\u3002<\/h3>\n<h4>\u767b\u9332\u753b\u9762<\/h4>\n<p>rich_text_area\u3068\u3044\u3046\u30d8\u30eb\u30d1\u30fc\u3092\u4f7f\u3048\u3070\u5b9f\u88c5\u304c\u53ef\u80fd\u3067\u3059\u3002\u3053\u308c\u304cTrix\u30a8\u30c7\u30a3\u30bf\u3068\u3044\u3046\u30a8\u30c7\u30a3\u30bf\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">  &lt;div class=\"field\"&gt;\r\n    &lt;%= form.rich_text_area :content %&gt;\r\n  &lt;\/div&gt;<\/pre>\n<h4>\u8a73\u7d30\u753b\u9762<\/h4>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true  \">&lt;p&gt;\r\n  &lt;strong&gt;Content:&lt;\/strong&gt;\r\n  &lt;%= @\u30e2\u30c7\u30eb\u540d.content %&gt;\r\n&lt;\/p&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"has_rich_text\u3092\u4f7f\u3046 \u4f7f\u7528\u3057\u305f\u3044\u30e2\u30c7\u30eb\u540d\u306b\u5bfe\u3057\u3066\u300chas_rich_text\u300d\u3092\u5ba3\u8a00\u3057\u307e\u3059\u3002\u3053\u308c\u3060\u3051\u3067\u30e2\u30c7\u30eb\u306b\u5bfe\u3057\u3066\u30ea\u30c3\u30c1\u30c6\u30ad\u30b9\u30c8\u3092\u6301\u305f\u305b\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u975e\u5e38\u306b\u7c21\u5358\u3067\u3059\u3088\u306d\u3002 class \u30e2\u30c7\u30eb\u540d &lt; [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/11371"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11371"}],"version-history":[{"count":9,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/11371\/revisions"}],"predecessor-version":[{"id":20510,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/11371\/revisions\/20510"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11371"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}