From 03b1010149520d3da85521f9e3a11a9d5ff2d2a8 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 28 Jun 2015 14:59:37 +0200 Subject: [PATCH] books index and simple db configuration --- .Gemfile.swp | Bin 12288 -> 12288 bytes Gemfile | 5 ++++- Gemfile.lock | 4 ++-- app/controllers/books_controller.rb | 6 +++++- app/controllers/static_pages_controller.rb | 2 +- app/models/book.rb | 1 + app/views/books/index.html.erb | 14 ++++++++++++++ config/environment.rb | 5 ----- 8 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 app/views/books/index.html.erb diff --git a/.Gemfile.swp b/.Gemfile.swp index 4af8a3931f0b281c43b0222f5521256f5bc8aee0..e0ef2c93177905c15c12223f63d804636f19c76f 100644 GIT binary patch delta 349 zcmZ9{ze@rE7{>8OC{WYR7Kes7a5xD1AsMx_1`TdyK|?CZA=qi>QA^PE2b4t6T1#sY z2Q~KdALt(_YOA5LXh;b9DowrcftTlbm)Fnx`DAf4HYyY#E_+ z(3ki$HX{+~8SOURzG9vX=@HjBMgu$8Mi!F@qtz=t;1;`B!!#`1$E9apVr!t` z(%@nrKyeY>L?I{t;ej6Dk0xYcj(hu6Gp^7`dN=i}^ uaN*#S_V~pBeYB880&&b4`-u@UxW*-7UfXcod%Clf+mO9Z^_<;FI)4Hx!Yv;F diff --git a/Gemfile b/Gemfile index 679e082..6748838 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,9 @@ source 'https://rubygems.org' -gem 'magic_multi_connections' +#gem 'magic_multi_connections' +gem 'will_paginate' +#gem 'bootstrap-will_paginate' + # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.2' diff --git a/Gemfile.lock b/Gemfile.lock index 6096249..edf97d0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,7 +66,6 @@ GEM json (1.8.3) loofah (2.0.2) nokogiri (>= 1.5.9) - magic_multi_connections (1.2.1) mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.6.1) @@ -138,6 +137,7 @@ GEM binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + will_paginate (3.0.7) PLATFORMS ruby @@ -147,7 +147,6 @@ DEPENDENCIES coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails - magic_multi_connections rails (= 4.2.2) sass-rails (~> 5.0) sdoc (~> 0.4.0) @@ -156,6 +155,7 @@ DEPENDENCIES turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) + will_paginate BUNDLED WITH 1.10.4 diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 1a0d2cf..4b7aae8 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,7 +1,11 @@ class BooksController < ApplicationController def show - @book = Calibre::Book.find(params[:id]) + @book = Book.find(params[:id]) + end + + def index + @books = Book.paginate(page: params[:page]) end end diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 486c329..5cb4c92 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,7 +1,7 @@ class StaticPagesController < ApplicationController def home @title = "Home" - @books_count = Calibre::Book.count + @books_count = Book.count end def about diff --git a/app/models/book.rb b/app/models/book.rb index 6f68b44..0044c2f 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,2 +1,3 @@ class Book < ActiveRecord::Base + establish_connection Rails.configuration.database_configuration["calibre"] end diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000..0c1deac --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,14 @@ +

All books

+ +<%= will_paginate %> + +
    + <% @books.each do |book| %> +
  • + <%= link_to book.title, book %> +
  • + <% end %> +
+ +<%= will_paginate %> + diff --git a/config/environment.rb b/config/environment.rb index 87d119e..e0e72d2 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -6,8 +6,3 @@ Rails.application.initialize! ENV['GEM_PATH']='/home/meutel/gems/:/usr/local/lib/ruby/gems/2.1/' ENV['GEM_HOME']='/home/meutel/gems' -require 'magic_multi_connections' - -module Calibre - establish_connection :calibre -end