views:

333

answers:

3

I tried the following code but it doesn't work

class BlogsController < ApplicationController
  def index
    #@entry_pages = Paginator.new(self, Entry.count, 10, params[:page])
    @entries = Entry.find(:all,
    #:limit => @entry_pages.items_per_page,
    #:offset => @entry_pages.current.offset,
    :order => 'entries.created_at DESC',
    :include => :user)
  end
end

This is the blog view

<h1>Recently updated blogs</h1>
<% @entries.each do |entry| %>
<p>
<%= link_to entry.user.username, entries_url(:user_id => entry.user) %><br />
'<%= entry.title %>' was posted <%= time_ago_in_words(entry.created_at) %> ago
</p>
<% end %>

I want the items to be paginated like this:

<<  [1][2][3]  >>
+12  A: 

Give the will_paginate GEM a try. It provides all the features you need to paginate your blog entries.

Simone Carletti
+1 will_paginate is a classic plugin for rails
Lukas Stejskal
A: 

I can recommend the paginating_find plugin. Here's a tutorial:

http://www.igvita.com/2006/09/10/faster-pagination-in-rails/

Looks like it's now hosted on github.com:

http://github.com/alexkwolfe/paginating_find/tree/master

Olly
A: 

if i used php like :

$query="Select * from news"; open(); $hasil=query($query); $jmlhalaman=ceil(mysql_num_rows($hasil)/$pph); close();

if(!isset($_GET['page'])){ 
 $page=0;
}else{
 $page=$_GET['page'];
}

$offset=$page*$pph;
$query="Select * from news order by newsid DESC LIMIT $offset,$pph";
open();
$hasil=query($query);
close();

while($data=mysql_fetch_array($hasil)){ 
 $TITLE=$data["title"];
 $TEXT1=$data["text1"];
 $DTIME=$data["dtime"];

 echo $TEXT1;
 echo $DTIME ;

 echo "<a href=read_more.php?newsid=$data[newsid]>"; 

echo "<b>Page :</b>";

for($i=0;$i<$jmlhalaman;$i++)

{

 echo "[<a href='info.php?page=$i'>".$i."</a>]";

}
?>

result is page [0][1][2][3]

what about rails, if i used without will_paginate??

i want create by my self. and i dont know how to write phpcode convert to rails

$pph=5;
$query="Select * from news"; open(); $hasil=query($query); $jmlhalaman=ceil(mysql_num_rows($hasil)/$pph); .......

where i must write the code ?in controller, view, helper or model .. and please give me for example code

please help me ..

Kuya