{"id":8032,"date":"2019-12-07T19:39:00","date_gmt":"2019-12-07T10:39:00","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=8032"},"modified":"2023-05-27T22:53:57","modified_gmt":"2023-05-27T13:53:57","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%80%8c%e3%83%9a%e3%83%bc%e3%82%b8%e3%83%b3%e3%82%b0%e3%80%8d%e3%81%ae%e5%ae%9f%e8%a3%85%ef%bc%88kaminari","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=8032","title":{"rendered":"\u3010Ruby on Rails\u3011\u300c\u30da\u30fc\u30b8\u30f3\u30b0\u300d\u306e\u5b9f\u88c5\uff08kaminari)"},"content":{"rendered":"<p>Rails\u3067\u30da\u30fc\u30b8\u30f3\u30b0\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u306fkaminari\u3068\u3044\u3046gem\u304c\u6700\u3082\u6709\u540d\u3067\u3059\u3002<\/p>\n<h2>kaminari\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>Gemfile\u306b\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">gem 'kaminari'<\/pre>\n<p>bundle\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">bundle<\/pre>\n<h2>\u30da\u30fc\u30b8\u30f3\u30b0\u306e\u5b9f\u88c5<\/h2>\n<h3>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5074<\/h3>\n<h4>page\u30b9\u30b3\u30fc\u30d7<\/h4>\n<p>\u30da\u30fc\u30b8\u756a\u53f7\u306f\u300cparams[:page]\u300d\u3067\u753b\u9762\u304b\u3089\u6e21\u3055\u308c\u3066\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u691c\u7d22\u7d50\u679c\u306e\u5909\u6570.page(params[:params])<\/pre>\n<p>kaminari\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308b<span style=\"color: #ff0000;\"><strong>page\u3068\u3044\u3046\u30b9\u30b3\u30fc\u30d7<\/strong><\/span>\u3092\u4f7f\u3046\u3068\u7c21\u5358\u306b\u753b\u9762\u304b\u3089\u9001\u3089\u308c\u3066\u304d\u305f\u30c7\u30fc\u30bf\u7bc4\u56f2\u306e\u30c7\u30fc\u30bf\u3092\u62bd\u51fa\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h4>per\u30b9\u30b3\u30fc\u30d7<\/h4>\n<pre class=\"lang:default decode:true \">\u691c\u7d22\u7d50\u679c\u5909\u6570.per(\u8868\u793a\u4ef6\u6570\uff09<\/pre>\n<p>\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u8868\u793a\u4ef6\u6570\u5206\u306e\u691c\u7d22\u7d50\u679c\u3060\u3051\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u30d3\u30e5\u30fc\u5074<\/h3>\n<h4>paginate\u30d3\u30e5\u30fc\u30d8\u30eb\u30d1\u30fc<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>\u300c\u73fe\u5728\u3069\u306e\u30da\u30fc\u30b8\u3092\u8868\u793a\u3057\u3066\u3044\u308b\u304b\u306e\u60c5\u5831\u300d<\/strong><\/span>\u3068<span style=\"color: #ff0000;\"><strong>\u300c\u4ed6\u306e\u30da\u30fc\u30b8\u306b\u79fb\u52d5\u3059\u308b\u305f\u3081\u306e\u30ea\u30f3\u30af\u300d<\/strong><\/span>\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>erb\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">&lt;%= paginate \u4e00\u89a7\u8868\u793a\u5bfe\u8c61\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8\uff08\u4f8b\uff1a@users) %&gt;<\/pre>\n<h4>page_entries_info\u30d3\u30e5\u30fc\u30d8\u30eb\u30d1\u30fc<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>\u300c\u5168\u30c7\u30fc\u30bf\u304c\u4f55\u4ef6\u306a\u306e\u304b\u300d<\/strong><\/span>\u3068\u3044\u3046\u60c5\u5831\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u65e5\u672c\u8a9e\u5316<\/h3>\n<p>kaminari\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u82f1\u8a9e\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u65e5\u672c\u8a9e\u5316\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>config\/application.rb<\/h4>\n<p>\u524d\u63d0\u3068\u3057\u3066\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">module App\r\n  class Application &lt; Rails::Application\r\n    # Settings in config\/environments\/* take precedence over those specified here.\r\n    # Application configuration should go into files in config\/initializers\r\n    # -- all .rb files in that directory are automatically loaded.\r\n    config.i18n.default_locale = :ja \u2605\u8ffd\u52a0\r\n  end\r\nend<\/pre>\n<p>config\/locales\/ja.yml\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066<span style=\"color: #ff0000;\"><strong>kaminari\u5c02\u7528\u306e\u7ffb\u8a33\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><span style=\"color: #000000;\">\u5185\u5bb9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5185\u5bb9\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/span><\/span><\/p>\n<pre class=\"lang:default decode:true\">ja:\r\n  views:\r\n    pagination:\r\n      first: '\u6700\u521d'\r\n      last: '\u6700\u5f8c'\r\n      previous: '\u524d'\r\n      next: '\u6b21'\r\n      truncate: '...'\r\n<\/pre>\n<h3>\u30da\u30fc\u30b8\u5168\u4f53\u306e\u8868\u793a\u4ef6\u6570\u306e\u8a2d\u5b9a<\/h3>\n<p>\u30e2\u30c7\u30eb\u5225\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306e1\u30da\u30fc\u30b8\u3042\u305f\u308a\u306e\u8868\u793a\u4ef6\u6570\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h4>\u30e2\u30c7\u30eb\u5225\u306e\u8a2d\u5b9a\uff08app\/models\/\u30e2\u30c7\u30eb\u540d.rb\uff09<\/h4>\n<pre class=\"lang:default decode:true \">paginates_per 1\u30da\u30fc\u30b8\u3042\u305f\u308a\u306e\u8868\u793a\u4ef6\u6570<\/pre>\n<h4>\u5168\u4f53\u8a2d\u5b9a<\/h4>\n<p>\u307e\u305f\u3001\u5168\u4f53\u306e1\u30da\u30fc\u30b8\u3042\u305f\u308a\u306e\u8868\u793a\u4ef6\u6570\u3092\u5909\u3048\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">rails g kaminari:config<\/pre>\n<p>\u300cconfig\/initializers\/kaminari_config.rb\u300d\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u305d\u3053\u306b\u4e0b\u8a18\u8a2d\u5b9a\u3092\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">config.default_per_page = 1\u30da\u30fc\u30b8\u3042\u305f\u308a\u306e\u8868\u793a\u4ef6\u6570<\/pre>\n<h2>\u30c7\u30b6\u30a4\u30f3\u306e\u8abf\u6574<\/h2>\n<p>kaminari\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u5473\u6c17\u306a\u3044\u30c7\u30b6\u30a4\u30f3\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002paginate\u30d3\u30e5\u30fc\u30d8\u30eb\u30d1\u30fc\u306f\u3044\u304f\u3064\u304b\u306e<span style=\"color: #ff0000;\"><strong>\u300c\u30d1\u30fc\u30b7\u30e3\u30eb\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u300d<\/strong><\/span>\u3068\u3044\u3046\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u3067\u9078\u629e\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u300cbootstrap\u300d\u306e\u30d1\u30fc\u30b7\u30e3\u30eb\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">rails g kaminari:views bootstrap4<\/pre>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u304b\u3063\u3053\u3044\u3044\u30c7\u30b6\u30a4\u30f3\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-8041\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2019\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2019-12-07-20.01.36.png\" alt=\"\" width=\"406\" height=\"102\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2019\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2019-12-07-20.01.36.png 406w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2019\/12\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2019-12-07-20.01.36-300x75.png 300w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"Rails\u3067\u30da\u30fc\u30b8\u30f3\u30b0\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u306fkaminari\u3068\u3044\u3046gem\u304c\u6700\u3082\u6709\u540d\u3067\u3059\u3002 kaminari\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb Gemfile\u306b\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u8ffd\u8a18\u3057\u307e\u3059\u3002 gem 'kaminari' bundle\u3057\u307e\u3059\u3002 bundl [&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\/8032"}],"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=8032"}],"version-history":[{"count":14,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8032\/revisions"}],"predecessor-version":[{"id":20528,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8032\/revisions\/20528"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8032"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}