-
Notifications
You must be signed in to change notification settings - Fork 16
Домашнее Задание 1 #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class BooksController < ApplicationController | ||
| def index | ||
| page = params[:page].to_i.positive? ? params[:page].to_i : 1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Методу page(), который добавляет гем Kaminary можно сразу передать params[:page] - он обработает все случаи: отрицательные значение, nil, просто вандальные параметры. Т.е. можем избавиться вот от этой строки page = params[:page].to_i.positive? ? params[:page].to_i : 1 |
||
|
|
||
| @books = Book.all.page(page) | ||
|
|
||
| render formats: :json | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| json.array! @books, :id, :title |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ default: &default | |
| postgre: &postgre | ||
| host: <%= ENV.fetch('POSTGRES_HOST', 'localhost') %> | ||
| port: <%= ENV.fetch('POSTGRES_PORT', '5432') %> | ||
| username: <%= ENV.fetch('POSTGRES_USER') { 'igorsimdyanov' } %> | ||
| password: <%= ENV.fetch('POSTGRES_PASSWORD') { '' } %> | ||
| username: <%= ENV.fetch('POSTGRES_USER') { 'postgres' } %> | ||
| password: <%= ENV.fetch('postgres') { '' } %> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В config/database.yml помоему опечатка в следующей строке password: <%= ENV.fetch('postgres') { '' } %>Тут лучше оставить значение переменной окружения POSTGRES_PASSWORD, если нужно установить пароль, то лучше это сделать в блоке метода fetch password: <%= ENV.fetch('POSTGRES_PASSWORD') { 'postgres' } %> |
||
|
|
||
| development: | ||
| <<: *default | ||
|
|
@@ -17,6 +17,7 @@ development: | |
|
|
||
| test: | ||
| <<: *default | ||
| <<: *postgre | ||
| database: library_test | ||
|
|
||
| production: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Kaminari.configure do |config| | ||
| config.default_per_page = Settings.app.items_per_page | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не очень понравился выбор в виде jbuilder - он конечно работает из коробки и хорошо описан, но уж больно он медленный по сравнению с другими сериалайзерами. У нас он сейчас на проекте, очень страдаем от его скорости и везде где только можно переходим на alab (у которого Си под капотом)