[RubyOnRails]ページネーション-kaminari導入手順

https://github.com/kaminari/kaminari

Gemfileの設定

Gemfile

gem 'kaminari'
bundle install

コントローラーの設定

  def index
    @posts = Post.all.order(created_at: :desc)
    @posts = Post.page(params[:page]).per(10)
  end

ビューの設定

<% @posts.each do |post| %>
 <div class="panel panel-success">
   <div class="panel-body">
    <%= link_to(post.content,"/posts/#{post.id}") %>
   </div>
   <div class="panel-footer">content_description</div>
 </div>
<% end %>
<%= paginate @posts %>

[RubyOnRails]本番サーバー構築手順(GitHub->Heroku編)

Railsの設定

Gemfileの設定

#sqlite3 # <-コメントアウトする

group :development, :test do
  gem 'sqlite3' # <-追加する
end

group :production do
  gem 'pg' # <-追加する
end

config/database.ymlの設定

# 追加する
production:
  <<: *default
  adapter: postgresql
  encoding: unicode
  pool: 5

config/environments/production.rbの設定

# false → trueに変更
config.assets.compile = true

Git

git init
git add -A
git commit -m "(コメント)"

Heroku

heroku login
heroku create (サービス名)

デプロイ

git push heroku master
heroku run rails db:migrate