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.new(params[:chatuser])
if Voicechat.find(@chatuser.voicechat_id).password =@chatuser.password
if @chatuser.save
flash[:notice] = ''Sign in Successfull..''
@chatusers = Chatuser.find(:all, :conditions => ["voicechat_id
= @chatuser.voicechat_id"])
redirect_to :action=> ''list''
else
render :action => ''new''
end
else
flash[:notice]=''Plz enter correct password.''
render :action => ''new''
end
end
chatusers is a table in the database...
def list
@chatuser_pages, @chatusers=paginate( :chatusers, :conditions=>["
voicechat_id = @chatuser.voicechat_id "],:per_page=>18)
end
chatusers is a table in the database...in 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
key..............
So plz anyone help me out.....thanks in advance.....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 6/27/07, mani <mani.narsampet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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.new(params[:chatuser]) > > if Voicechat.find(@chatuser.voicechat_id).password => @chatuser.password > if @chatuser.save > flash[:notice] = ''Sign in Successfull..'' > @chatusers = Chatuser.find(:all, :conditions => ["voicechat_id > = @chatuser.voicechat_id"]) > redirect_to :action=> ''list'' > else > render :action => ''new'' > end > else > flash[:notice]=''Plz enter correct password.'' > render :action => ''new'' > > end > end > > chatusers is a table in the database... > > def list > @chatuser_pages, @chatusers=paginate( :chatusers, :conditions=>[" > voicechat_id = @chatuser.voicechat_id "],:per_page=>18) > endYour 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 character. you should also look at the "will_paginate" plugin (http://errtheblog.com/post/4791), it''s much better than the rails built in pagination. Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 create...it 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 @chatuser.save 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---