Hi, I am looking for ideas on how to remove the last item from a paginated page when a new item is inserted, thus leaving only 10 elements on the page. Currently I have a form that inserts with AJAX, but as expected, each post added to the page just increases the number of posts leaving 11 on a page that should only be displaying 10. I have unique ID''s for each post (e.g. post_4, post_5, etc) and the post with the lowest number is on the bottom of the page, can anyone think of a way to make the last post disappear when the new post is added? Basically what i need to do is do a page.hide ''page_<% lowest id %>'' - where the lowest id is not a known integer. Ideas? ~Jamie
On Friday, July 14, 2006, at 3:04 PM, Jamie Quint wrote:>Hi, > >I am looking for ideas on how to remove the last item from a >paginated page when a new item is inserted, thus leaving only 10 >elements on the page. > >Currently I have a form that inserts with AJAX, but as expected, >each post added to the page just increases the number of posts >leaving 11 on a page that should only be displaying 10. > >I have unique ID''s for each post (e.g. post_4, post_5, etc) and the >post with the lowest number is on the bottom of the page, can anyone >think of a way to make the last post disappear when the new post is added? > >Basically what i need to do is do a page.hide ''page_<% lowest id %>'' > - where the lowest id is not a known integer. > >Ideas? > >~Jamie >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsYou could just re-render the 10 items on the page and replace all of them. _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
I''m no expert with Rails or Ruby (I''ve only been using it for about a week), but it sounds like you want to do something like this: http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates Cody adds an item to the list but its always the same. To change it you could just pass the post details through the action then page.hide " page_#{@lowest_id}" and then page.insert_html "page_#{@newpost.title" or something. (The syntax for insert_html isn''t correct, but you should get the idea) Thought it might help! It probably won''t but that''s where I''d start. Chris On 15 Jul 2006 00:20:18 -0000, Kevin Olbrich < devlists-rubyonrails@devlists.com> wrote:> > > On Friday, July 14, 2006, at 3:04 PM, Jamie Quint wrote: > >Hi, > > > >I am looking for ideas on how to remove the last item from a > >paginated page when a new item is inserted, thus leaving only 10 > >elements on the page. > > > >Currently I have a form that inserts with AJAX, but as expected, > >each post added to the page just increases the number of posts > >leaving 11 on a page that should only be displaying 10. > > > >I have unique ID''s for each post (e.g. post_4, post_5, etc) and the > >post with the lowest number is on the bottom of the page, can anyone > >think of a way to make the last post disappear when the new post is > added? > > > >Basically what i need to do is do a page.hide ''page_<% lowest id %>'' > > - where the lowest id is not a known integer. > > > >Ideas? > > > >~Jamie > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > You could just re-render the 10 items on the page and replace all of them. > > _Kevin > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- 3202-4 Sydney University Village 90 Carillon Avenue Newtown 2042 NSW, Australia T: 9036-4302 M: 04241-21343 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060715/21d0bbf0/attachment-0001.html
This is what I am already doing, I just need a way to get the ID of the last post so I can hide it when a new one is made. If I could get the ID of the lowest post on the page I would be able to do that. ~Jamie On Jul 14, 2006, at 7:59 PM, Chris Lloyd wrote:> I''m no expert with Rails or Ruby (I''ve only been using it for about > a week), but it sounds like you want to do something like this: > http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates > > Cody adds an item to the list but its always the same. To change it > you could just pass the post details through the action then > page.hide "page_#{@lowest_id}" and then page.insert_html " page_# > {@newpost.title" or something. (The syntax for insert_html isn''t > correct, but you should get the idea) > > Thought it might help! It probably won''t but that''s where I''d start. > > Chris > > > On 15 Jul 2006 00:20:18 -0000, Kevin Olbrich <devlists- > rubyonrails@devlists.com> wrote: > > On Friday, July 14, 2006, at 3:04 PM, Jamie Quint wrote: > >Hi, > > > >I am looking for ideas on how to remove the last item from a > >paginated page when a new item is inserted, thus leaving only 10 > >elements on the page. > > > >Currently I have a form that inserts with AJAX, but as expected, > >each post added to the page just increases the number of posts > >leaving 11 on a page that should only be displaying 10. > > > >I have unique ID''s for each post (e.g. post_4, post_5, etc) and the > >post with the lowest number is on the bottom of the page, can anyone > >think of a way to make the last post disappear when the new post > is added? > > > >Basically what i need to do is do a page.hide ''page_<% lowest id %>'' > > - where the lowest id is not a known integer. > > > >Ideas? > > > >~Jamie > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > You could just re-render the 10 items on the page and replace all > of them. > > _Kevin > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > 3202-4 Sydney University Village > 90 Carillon Avenue > Newtown 2042 > NSW, Australia > T: 9036-4302 > M: 04241-21343 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060716/1d240eae/attachment.html
I guess I would save the scriptaculous overhead if I did it this way, but it seems like re-rendering everything would defeat the purpose of using ajax in the first place (avert unnecessary page-loads and provide a smooth UI). ~Jamie On Jul 14, 2006, at 5:20 PM, Kevin Olbrich wrote:> > On Friday, July 14, 2006, at 3:04 PM, Jamie Quint wrote: >> Hi, >> >> I am looking for ideas on how to remove the last item from a >> paginated page when a new item is inserted, thus leaving only 10 >> elements on the page. >> >> Currently I have a form that inserts with AJAX, but as expected, >> each post added to the page just increases the number of posts >> leaving 11 on a page that should only be displaying 10. >> >> I have unique ID''s for each post (e.g. post_4, post_5, etc) and the >> post with the lowest number is on the bottom of the page, can anyone >> think of a way to make the last post disappear when the new post >> is added? >> >> Basically what i need to do is do a page.hide ''page_<% lowest id %>'' >> - where the lowest id is not a known integer. >> >> Ideas? >> >> ~Jamie >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > You could just re-render the 10 items on the page and replace all > of them. > > _Kevin > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
When the controller saves the actual record, the instance variable that contains the record should have the ID now. @post = Post.new(params[:post]) @post.save @last_post_id = @post.id Then in the data loaded by the remote form you could simply: Element.hide("post_<%= @last_post_id %>") Hope this helps, Rick Martinez On 7/16/06, Jamie Quint <jsquintz@gmail.com> wrote:> > This is what I am already doing, I just need a way to get the ID of the last > post so I can hide it when a new one is made. If I could get the ID of the > lowest post on the page I would be able to do that. > > ~Jamie > > > On Jul 14, 2006, at 7:59 PM, Chris Lloyd wrote: > I''m no expert with Rails or Ruby (I''ve only been using it for about a week), > but it sounds like you want to do something like this: > http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates > > Cody adds an item to the list but its always the same. To change it you > could just pass the post details through the action then page.hide > "page_#{@lowest_id}" and then page.insert_html " page_#{@newpost.title" or > something. (The syntax for insert_html isn''t correct, but you should get the > idea) > > Thought it might help! It probably won''t but that''s where I''d start. > > Chris > > > On 15 Jul 2006 00:20:18 -0000, Kevin Olbrich > <devlists-rubyonrails@devlists.com> wrote: > > > > On Friday, July 14, 2006, at 3:04 PM, Jamie Quint wrote: > > >Hi, > > > > > >I am looking for ideas on how to remove the last item from a > > >paginated page when a new item is inserted, thus leaving only 10 > > >elements on the page. > > > > > >Currently I have a form that inserts with AJAX, but as expected, > > >each post added to the page just increases the number of posts > > >leaving 11 on a page that should only be displaying 10. > > > > > >I have unique ID''s for each post (e.g. post_4, post_5, etc) and the > > >post with the lowest number is on the bottom of the page, can anyone > > >think of a way to make the last post disappear when the new post is > added? > > > > > >Basically what i need to do is do a page.hide ''page_<% lowest id %>'' > > > - where the lowest id is not a known integer. > > > > > >Ideas? > > > > > >~Jamie > > >_______________________________________________ > > >Rails mailing list > > >Rails@lists.rubyonrails.org > > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > You could just re-render the 10 items on the page and replace all of them. > > > > _Kevin > > > > -- > > Posted with http://DevLists.com. Sign up and save your mailbox. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > 3202-4 Sydney University Village > 90 Carillon Avenue > Newtown 2042 > NSW, Australia > T: 9036-4302 > M: 04241-21343 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Rick Martinez Director of Technology Complexity Gaming