diff --git a/.gitignore b/.gitignore index 2f761fe..c9f05b0 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ coverage config/settings.local.yml config/settings/*.local.yml config/environments/*.local.yml + +# IDE files +/.idea/* diff --git a/Gemfile b/Gemfile index fc76bca..334ef91 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,9 @@ gem 'activerecord-import' gem 'sprockets-rails' gem 'slim-rails' +# Serializers +gem 'jbuilder' + # Распаковка архивов gem 'rubyzip', require: 'zip' diff --git a/Gemfile.lock b/Gemfile.lock index 63e5241..164ad56 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,9 @@ GEM irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) + jbuilder (2.13.0) + actionview (>= 5.0.0) + activesupport (>= 5.0.0) jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -460,6 +463,7 @@ DEPENDENCIES factory_bot_rails fasterer ffaker + jbuilder parallel pg pry-byebug diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..6c1ffcf --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,9 @@ +class BooksController < ApplicationController + def index + page = params[:page].to_i.positive? ? params[:page].to_i : 1 + + @books = Book.all.page(page) + + render formats: :json + end +end diff --git a/app/views/books/index.json.jbuilder b/app/views/books/index.json.jbuilder new file mode 100644 index 0000000..223ad63 --- /dev/null +++ b/app/views/books/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @books, :id, :title diff --git a/config/database.yml b/config/database.yml index 48f30ee..ec725ed 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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') { '' } %> development: <<: *default @@ -17,6 +17,7 @@ development: test: <<: *default + <<: *postgre database: library_test production: diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb new file mode 100644 index 0000000..0c0e1ac --- /dev/null +++ b/config/initializers/kaminari_config.rb @@ -0,0 +1,3 @@ +Kaminari.configure do |config| + config.default_per_page = Settings.app.items_per_page +end diff --git a/config/routes.rb b/config/routes.rb index ae608d2..e7e9b52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,8 @@ devise_for :admin_users root to: redirect('/admin/') # if Routing::Admin.present? + + get "books/(:page)" => 'books#index' # namespace :admin do # # root to: 'home#index', as: :root