Forum: Ruby on Rails Pagination links with separator

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
548240c1431285c235ecf711293a7311?d=identicon&s=25 Yash (Guest)
on 2006-04-18 15:14
Hi,

I have @result_pages and @results obtained from paginate in an action. I
want to show the pages as
1 | 2 | 3 | 4 >
The fifth page will show:
< 5 | 6 | 7 | 8 >
and so on.
How exactly do I render the paginator to give this effect? I guess I
will have to use pagination_links_each. But being new to Rails, I need
help.

Thanks,
Yash
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-04-18 16:12
(Received via mailing list)
On Apr 18, 2006, at 15:14, Yash wrote:

> will have to use pagination_links_each. But being new to Rails, I need
I wrote this helper for an application where pagination and ordering
were done through Ajax:

   # Returns the links to pages for paginated listings.
   def pagination_links_remote(options={})
     paginator = options[:paginator]
     actions = []
     1.upto(paginator.page_count) do |n|
       if paginator[n] == paginator.current_page
         actions << n.to_s
       else
         options[:url][:page] = n
         actions << link_to_remote(n.to_s, options)
       end
     end
     "[ #{actions.join(' | ')} ]"
   end

It was invoked this way:

   <% if @employee_pages.page_count > 1 %>
   <p>
     <%=
       pagination_links_remote(
         :paginator => @employee_pages,
         :update    => 'listing',
         :url       => {
           :action    => 'listing',
           :order_by  => @current_order_by,
           :direction => @current_direction,
         }
       )
     %>
   </p>
   <% end %>

As you see some details come from the usage I wanted, but that's the
idea.

-- fxn
This topic is locked and can not be replied to.