From d629153e0f3fdffce7d8995fc3ef41f63ae78d89 Mon Sep 17 00:00:00 2001 From: Meutel Date: Mon, 29 Jun 2015 18:58:02 +0200 Subject: [PATCH] display items on home page (AJAX) --- app/controllers/authors_controller.rb | 4 ++++ app/controllers/books_controller.rb | 4 ++++ app/controllers/series_controller.rb | 4 ++++ app/views/authors/_index.html.erb | 9 +++++++++ app/views/authors/index.html.erb | 11 +---------- app/views/authors/index.js.erb | 1 + app/views/books/_index.html.erb | 12 ++++++++++++ app/views/books/index.html.erb | 14 +------------- app/views/books/index.js.erb | 1 + app/views/series/_index.html.erb | 9 +++++++++ app/views/series/index.html.erb | 11 +---------- app/views/series/index.js.erb | 1 + app/views/static_pages/home.html.erb | 8 +++++--- 13 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 app/views/authors/_index.html.erb create mode 100644 app/views/authors/index.js.erb create mode 100644 app/views/books/_index.html.erb create mode 100644 app/views/books/index.js.erb create mode 100644 app/views/series/_index.html.erb create mode 100644 app/views/series/index.js.erb diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index 533b782..1c0ec9f 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -8,6 +8,10 @@ class AuthorsController < ApplicationController def index @authors = Author.paginate(page: params[:page]) @title = "Authors" + respond_to do |format| + format.html + format.js + end end end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index a4a694f..5081477 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -8,6 +8,10 @@ class BooksController < ApplicationController def index @books = Book.paginate(page: params[:page]) @title = "Books" + respond_to do |format| + format.html + format.js + end end end diff --git a/app/controllers/series_controller.rb b/app/controllers/series_controller.rb index eb28280..a8bdbf7 100644 --- a/app/controllers/series_controller.rb +++ b/app/controllers/series_controller.rb @@ -8,6 +8,10 @@ class SeriesController < ApplicationController def index @series = Serie.paginate(page: params[:page]) @title = "Series" + respond_to do |format| + format.html + format.js + end end end diff --git a/app/views/authors/_index.html.erb b/app/views/authors/_index.html.erb new file mode 100644 index 0000000..7e36c98 --- /dev/null +++ b/app/views/authors/_index.html.erb @@ -0,0 +1,9 @@ +<%= will_paginate %> + + + +<%= will_paginate %> diff --git a/app/views/authors/index.html.erb b/app/views/authors/index.html.erb index 322eff1..e8aefa0 100644 --- a/app/views/authors/index.html.erb +++ b/app/views/authors/index.html.erb @@ -1,11 +1,2 @@

Authors

- -<%= will_paginate %> - - - -<%= will_paginate %> +<%= render 'authors/index' %> diff --git a/app/views/authors/index.js.erb b/app/views/authors/index.js.erb new file mode 100644 index 0000000..41478db --- /dev/null +++ b/app/views/authors/index.js.erb @@ -0,0 +1 @@ +$("#items").html("<%= escape_javascript(render('authors/index')) %>"); diff --git a/app/views/books/_index.html.erb b/app/views/books/_index.html.erb new file mode 100644 index 0000000..03b71a5 --- /dev/null +++ b/app/views/books/_index.html.erb @@ -0,0 +1,12 @@ +<%= will_paginate %> + + + +<%= will_paginate %> + diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 0c1deac..e21e41d 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -1,14 +1,2 @@

All books

- -<%= will_paginate %> - - - -<%= will_paginate %> - +<%= render 'books/index' %> diff --git a/app/views/books/index.js.erb b/app/views/books/index.js.erb new file mode 100644 index 0000000..71a51d0 --- /dev/null +++ b/app/views/books/index.js.erb @@ -0,0 +1 @@ +$("#items").html("<%= escape_javascript(render('books/index')) %>"); diff --git a/app/views/series/_index.html.erb b/app/views/series/_index.html.erb new file mode 100644 index 0000000..45f0a89 --- /dev/null +++ b/app/views/series/_index.html.erb @@ -0,0 +1,9 @@ +<%= will_paginate %> + + + +<%= will_paginate %> diff --git a/app/views/series/index.html.erb b/app/views/series/index.html.erb index a2241fa..4493078 100644 --- a/app/views/series/index.html.erb +++ b/app/views/series/index.html.erb @@ -1,11 +1,2 @@

Series

- -<%= will_paginate %> - - - -<%= will_paginate %> +<%= render 'series/index' %> diff --git a/app/views/series/index.js.erb b/app/views/series/index.js.erb new file mode 100644 index 0000000..4301451 --- /dev/null +++ b/app/views/series/index.js.erb @@ -0,0 +1 @@ +$("#items").html("<%= escape_javascript(render('series/index')) %>"); diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index 12952a5..e7efe64 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -3,8 +3,10 @@

Browse <%= @books_count %> books

- <%= link_to "Books", books_path, class: "btn btn-lg btn-primary" %> - <%= link_to "Authors", authors_path, class: "btn btn-lg btn-primary" %> - <%= link_to "Series", series_path, class: "btn btn-lg btn-primary" %> + <%= link_to "Books", books_path, class: "btn btn-lg btn-primary", remote: true %> + <%= link_to "Authors", authors_path, class: "btn btn-lg btn-primary", remote: true %> + <%= link_to "Series", series_path, class: "btn btn-lg btn-primary", remote: true %>

+
+