Created
November 26, 2017 23:18
-
-
Save stuartambient/9208a2c16963bb382c6c31a328cfe7c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# route - | |
get '/pag' do | |
@all_album_links = paginate | |
@pages = {} | |
@all_album_links.each_slice(10).with_index do |x,i| | |
@pages.store("page #{i+1 }", "#{x}") | |
end | |
slim :pag | |
#end | |
end | |
# paginate which creates the array and returns it to the route | |
def paginate | |
num_links = Album.count | |
link_first_part = %q[<li class="page-item"><a class="page-link"] | |
link_second_part = %q[</a></li>] | |
@all_album_links = [] | |
pages = {} | |
num_links.times do |i| | |
i = i + 1 | |
ahref = "href=pag/page=#{i}>" | |
@all_album_links << "#{link_first_part}#{ahref}#{i.to_s}#{link_second_part}" | |
end | |
@all_album_links | |
end | |
# the call to the hash in the route. I have each_line because it says it's a string | |
# won't respond to each | |
-@pages["page 1"].each_line do |link| | |
== link | |
p "Pages - #{@pages["page 1"].class}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment