display items on home page (AJAX)
This commit is contained in:
parent
ee56518217
commit
d629153e0f
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
9
app/views/authors/_index.html.erb
Normal file
9
app/views/authors/_index.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="authors">
|
||||
<% @authors.each do |author| %>
|
||||
<li><%= link_to author.name, author %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
@ -1,11 +1,2 @@
|
||||
<h1>Authors</h1>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="authors">
|
||||
<% @authors.each do |author| %>
|
||||
<li><%= link_to author.name, author %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
||||
<%= render 'authors/index' %>
|
||||
|
1
app/views/authors/index.js.erb
Normal file
1
app/views/authors/index.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$("#items").html("<%= escape_javascript(render('authors/index')) %>");
|
12
app/views/books/_index.html.erb
Normal file
12
app/views/books/_index.html.erb
Normal file
@ -0,0 +1,12 @@
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="books">
|
||||
<% @books.each do |book| %>
|
||||
<li>
|
||||
<%= link_to book.title, book %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
@ -1,14 +1,2 @@
|
||||
<h1>All books</h1>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="books">
|
||||
<% @books.each do |book| %>
|
||||
<li>
|
||||
<%= link_to book.title, book %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
||||
<%= render 'books/index' %>
|
||||
|
1
app/views/books/index.js.erb
Normal file
1
app/views/books/index.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$("#items").html("<%= escape_javascript(render('books/index')) %>");
|
9
app/views/series/_index.html.erb
Normal file
9
app/views/series/_index.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="series">
|
||||
<% @series.each do |serie| %>
|
||||
<li><%= link_to serie.name, serie %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
@ -1,11 +1,2 @@
|
||||
<h1>Series</h1>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="series">
|
||||
<% @series.each do |serie| %>
|
||||
<li><%= link_to serie.name, serie %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
||||
<%= render 'series/index' %>
|
||||
|
1
app/views/series/index.js.erb
Normal file
1
app/views/series/index.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$("#items").html("<%= escape_javascript(render('series/index')) %>");
|
@ -3,8 +3,10 @@
|
||||
<h2>Browse <%= @books_count %> books</h2>
|
||||
|
||||
<p>
|
||||
<%= 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 %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="center container-fluid" id="items">
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user