hi, i have used following code in controller for pagination def view page = (params[:page] ||= 1).to_i items_per_page = 3 offset = (page - 1) * items_per_page @prods=Item.find_by_sql("select * from items order by id") @prod_pages = Paginator.new(self, @prods.length, items_per_page, page) @items = @prods[offset..(offset + items_per_page - 1)] end in view.rhtml file i have following code for showing items in view.rhtml and checkbox code <body> <%=start_form_tag (:id=>@item,:name=>''frmv'' ,:action=>''compare'')%> <%=@final%> <% if @prods != nil%> <center> <table border="1" cellspacing="5" align="center" height=40% width=50%> <tr align="center"> <td height=10%></td> </tr> <tr> <td colspan=4 align=''center'' bgcolor=''#abcdef''>Real Estate List</td> </tr> <% for p in @items%> <tr> <td> <%= h(p.id)%> </td> <td> <% if p.image != nil%> <img src="/images<%= h(p.image)%>" height=100% width=100%></img> <% else %> No Image <% end %> </td> <td> <%= h(p.description)%> </td> <td> <%= h(p.price)%> </td> <td> <%= check_box("chk1", p.id,{},"yes","no")%> </td> </tr> <% end%> <tr> <td> <%=submit_tag "Compare"%> </td> </tr> </table> <% if @prod_pages.page_count > 1 %> <%= pagination_links @prod_pages %> <% end %> <% else%> No items in shop. <% end%> </center> </table> <%=end_form_tag%> </body> -------------------------- to view selected data my code in controller is = def compare @data="" data = params[:chk1] data.each do |pid,flag| if flag == "1" @data << pid + "," end end if @data!="" @data=@data[0,@data.length-1] @newdata=Item.find_by_sql("select *from items where id in (" +@data +")") end -------------------------- problem is when i go to next page first page''s selected checkboxes becomes unselected, so what to do? my aim is to select items from multiple pages and get then on new page named Compare.rhtml to compare them. this problem is really frustrating, plz reply if anybody knows. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I didn''t go through your code really, but why don''t you use a session which is updated with an observe_form( or observe_field) on your check buttons. On 8 fév, 13:37, Jahnvi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi, i have used following code in controller for pagination > > def view > page = (params[:page] ||= 1).to_i > items_per_page = 3 > offset = (page - 1) * items_per_page > > @prods=Item.find_by_sql("select * from items order by id") > > @prod_pages = Paginator.new(self, @prods.length, items_per_page, page) > > @items = @prods[offset..(offset + items_per_page - 1)] > > end > > in view.rhtml file i have following code for showing items in view.rhtml > and checkbox code > > <body> > <%=start_form_tag (:id=>@item,:name=>''frmv'' ,:action=>''compare'')%> > <%=@final%> > <% if @prods != nil%> > <center> > <table border="1" cellspacing="5" align="center" height=40% > width=50%> > > <tr align="center"> > <td height=10%></td> > </tr> > <tr> > <td colspan=4 align=''center'' bgcolor=''#abcdef''>Real > Estate List</td> > </tr> > <% for p in @items%> > <tr> > <td> > <%= h(p.id)%> > </td> > <td> > <% if p.image != nil%> > <img src="/images<%= h(p.image)%>" > height=100% width=100%></img> > <% else %> > No Image > <% end %> > </td> > > <td> > <%= h(p.description)%> > </td> > <td> > <%= h(p.price)%> > </td> > <td> > <%= check_box("chk1", > p.id,{},"yes","no")%> > </td> > </tr> > <% end%> > <tr> > <td> > <%=submit_tag "Compare"%> > </td> > </tr> > </table> > <% if @prod_pages.page_count > 1 %> > <%= pagination_links @prod_pages %> > <% end %> > <% else%> > No items in shop. > <% end%> > > </center> > > </table> > <%=end_form_tag%> > </body> > > -------------------------- > to view selected data my code in controller is => > def compare > @data="" > data = params[:chk1] > > data.each do |pid,flag| > if flag == "1" > @data << pid + "," > end > end > > if @data!="" > @data=@data[0,@data.length-1] > @newdata=Item.find_by_sql("select *from items where id in (" +@data > +")") > end > -------------------------- > problem is when i go to next page first page''s selected checkboxes > becomes unselected, so what to do? my aim is to select items from > multiple pages and get then on new page named Compare.rhtml to compare > them. > > this problem is really frustrating, plz reply if anybody knows. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Because that might give problems when a user views this page from multiple tabs or browsers ? What you should do is add your checkbox selection states to your pagination links. This way they will get ''forwarded'' to the other pages. Not sure you''ll be able to do this with the standard pagination functionality. Piet.> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Charly > Sent: donderdag 8 februari 2007 13:47 > To: Ruby on Rails: Talk > Subject: [Rails] Re: Persist checked checkboxes in pagination > > > I didn''t go through your code really, but why don''t you use a > session which is updated with an observe_form( or > observe_field) on your check buttons. >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Charly wrote:> I didn''t go through your code really, but why don''t you use a session > which is updated with an observe_form( or observe_field) on your check > buttons.Hi Charly, I''ve got the same problem than Jahnvi, I''m losing my selected check_boxes when I move from one page to another in my pagination. I''ve taken a look at the observe_field solution that you proposed.... but I''m not able to find out how to solve my problem with it. May you help me a bit with this? I''ve got so stuck with it... Thanks a lot for your help, Monica -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---