Hello - I am using paginating_find trying to paginate my records My
CallsController index action is
def index
@calls = @current_user.calls.find(:all, :page => {:size =>
4, :current => params[:page]})
end
then in the index template for the calls view I have
<% @current_user.calls.each do |call| %>
- <%= link_to h(call.name), :action => 'show', :id
=> call %>
<% end %>
<%= @calls %>
<%= paginating_links(@calls) %>
I only have the <%= @calls %> to see what is in the @calls variable
to see if it is available to paginating_find but it isn’t. The
each.do loop gives links to all the current_user’s calls but I get no
paginating. I would like 4 per page. If I change the loop to
@calls.each do I get calls for all the users which is not what I want
and if I change the paginating_links to
paginating_links(@current_user.calls) I get the following error
undefined method `page’ for #Class:0x251dacc
Extracted source (around line #16):
13: <% end %>
14:
15: <%= @calls %>
16: <%= paginating_links(@current_user.calls) %>
17:
18:
19:
So my paginating_links is getting nothing to paginate from what I can
see althoug it doew list pages 1 and 2 as links
Any help out there please
Owen
So the problem is that @calls is not scoped to the @current_user?
Thank you so much for your reply Alexkwolf. Thants how I see it also
When I change the line before <%=
paginating_links(@current_users.calls) %>
to <%= @current_user.calls %> just to see what is in the variable i
get the following
<ol>
<li><a href="/calls/142">Vanessa</a></li>
<li><a href="/calls/168">Linnea</a></li>
<li><a href="/calls/169">Richard</a></li>
<li><a href="/calls/170">Linea</a></li>
<li><a href="/calls/171">Mark</a></li>
<li><a href="/calls/172">My friend</a></li>
<li><a href="/calls/173">Melvin</a></li>
<li><a href="/calls/174">Tuesday</a></li>
<li><a href="/calls/175">Tony lynn</a></li>
<li><a href="/calls/176">Lyn Lyn</a></li>
<li><a href="/calls/177">Marjorie</a></li>
</ol>
#<Call:0x20f4b44>#<Call:0x20f4a54>#<Call:0x20f4950>#<Call:
0x20f4874>#Call:0x20f4798#Call:0x20f46a8#Call:0x20f45b8#<Call:
0x20f44c8>#Call:0x20f43ec#Call:0x20f4310#Call:0x20f4234
1 <a href="/calls?page=2">2</a> <a href="/calls?page=3">3</a>
and if I change the line before to just <%= @calls %> i get
this avter the loop output
#
1 <a href="/calls?page=2">2</a> <a href="/calls?page=3">3</a>
So I am not sure what is happening allthough both times I get this
interesting output of numbers. Any idea would be greatly appreciated
Owen
On Jul 15, 5:49 am, “[email protected]” [email protected]
I think I may have figured it out
In my index.rhtml for app/views/calls I tried this code
<% @recent_calls = @current_user.calls.find(:all, :page => {:size
=> 4, :current => params[:page]}) %>
<ol>
<% @recent_calls.each do |c| %>
<li><%= link_to h(c.name), :action => 'show', :id =>
c.id %>
<% end %>
<%= paginating_links(@recent_calls) %>
and it gave me only the 10 calls associated with the current_user so I
have to try a few more things
and I want to have a previous link and a next link so I don’t have to
click on the page numbers.
So thanks for the interest and help and thanks to alex wolf for the
plug in for paginating_links that works for me