Forum: Ruby on Rails Pagination......

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
32883bb85bebc818a1794e90e8c1ec81?d=identicon&s=25 mani (Guest)
on 2007-06-27 13:54
(Received via mailing list)
hi all.. iam new to rails...

iam developing a app and unable to solve one problem..the problem is
regarding pagination....

im my app in controller class i have these two methods:

i have two tables one is chatusers and the other is
voicechats...chatusers foreign key refers voicechats..........the
below methods are present in chatuser controller........

def create
    @chatuser =[:chatuser])

    if Voicechat.find(@chatuser.voicechat_id).password ==
       flash[:notice] = 'Sign in Successfull..'
       @chatusers = Chatuser.find(:all, :conditions => ["voicechat_id
= @chatuser.voicechat_id"])
       redirect_to :action=> 'list'
      render :action => 'new'
flash[:notice]='Plz enter correct password.'
render :action => 'new'


chatusers is a table in the database...

def list
    @chatuser_pages, @chatusers=paginate( :chatusers, :conditions=>["
voicechat_id = @chatuser.voicechat_id "],:per_page=>18)

chatusers is a table in the which foreign key refers to
voicechats table...

my goals:
1) wen create action is taking place, only chatusers with that foreign
key (which is assigned to the new user) should be listed...... for
that i have edited the default list method...using conditions but it
isnt working.....instead it is not showing anything...even though some
records are present in chatusers table wid that foreign

So plz anyone help me out.....thanks in advance.....
0900e6a4828bd989f96427082c6c74ca?d=identicon&s=25 Mike Garey (random52k)
on 2007-06-27 22:10
(Received via mailing list)
On 6/27/07, mani <> wrote:
> below methods are present in chatuser controller........
>        redirect_to :action=> 'list'
> chatusers is a table in the database...
> def list
>     @chatuser_pages, @chatusers=paginate( :chatusers, :conditions=>["
> voicechat_id = @chatuser.voicechat_id "],:per_page=>18)
>   end

Your conditions parameter is wrong.. You're sending :conditions =>
["voicechat_id = @chatuser.voicechat_id"] which is exactly what's
going to show up in the mysql query, which of course will fail.. For
example, it'll generate something like:

select * from chatusers where voicechat_id = @chatuser.voicechat_id ...

which isn't valid sql..  You want to use the following:

:conditions => ["voicechat_id = ?", @chatuser.voicechat_id]

which will bind the @chatuser.voicechat_id value to the ? placeholder

you should also look at the "will_paginate" plugin
(, it's much better than the rails
built in pagination.

32883bb85bebc818a1794e90e8c1ec81?d=identicon&s=25 mani (Guest)
on 2007-06-29 07:33
(Received via mailing list)
hi mike...
thank u for ur valuable reply...

wen i wrote this line of code:

@chatuser_pages, @chatusers
=paginate(:chatusers, :conditions=>["voicechat_id=?",
@chatuser.voicechat_id],:per_page=>18) in the list method it is
showing following error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each

And wen i copy this code code and paste it in the create method and i
also renamed the list(int views folder) file to is working
and it is showing wat is required.....i donno y it is not showing the
in the first way...

 In create method... there is a line called  if it
means it is saving the record in the model... and after that it is
probabaly set to null automatically.. and may be thats y we were
unable to solve get @chatuser.voicechat_id.

Plz help me out to overcome this problem....thanks in advance..bye
32883bb85bebc818a1794e90e8c1ec81?d=identicon&s=25 mani (Guest)
on 2007-06-29 08:18
(Received via mailing list)
and one more thing... i think @chatuser is local to class and may be
that y its is not accessible outside...
can we anyway get the record id that is added recently..bcause if we
can get that we can replace @chatuser.voicechat_id
with Chatuser.find(id).voicechat_id ...... plz try to help me
out ...have a nice time bye
This topic is locked and can not be replied to.