Skip to content

Instantly share code, notes, and snippets.

@stuartambient
Created November 26, 2017 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartambient/9208a2c16963bb382c6c31a328cfe7c1 to your computer and use it in GitHub Desktop.
Save stuartambient/9208a2c16963bb382c6c31a328cfe7c1 to your computer and use it in GitHub Desktop.
# 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