Hi, My case is slightly more complex than below but I''ll give a simple example to describe the problem. There is a ''book'' table. A user can search for books by typing keywords for book title and author name in a form. For example: show all books that include the word ''peace'' in the title. The search results needs to be paginated. # controller will look roughly like this def search_results title = params[:search][:title] authorname = params[:search][:authorname] # form the sql query sql = ''select * from books... where title =... and author_id=... " # create paginator and results. I''ll be using a custom pagination here since it''s a find_by_sql. # I know how to do this, the problem is not here... @book_pages, @books = ... end now, the view includes first page of results, the pagination links with page number in the url and all... the problem is that when clicking on them (for example clicking on ''next page'') will never work since it doesn''t include the request parameter of the book anymore. There is no longer params[:search][:title] and params[:search][:authorname]. so clicking on ''/book/search_results/page=2'' will fail saying that params[:search][:title] is NIL... any idea how can i acheive this? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
On 9/25/06, Alon Goldshuv <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > My case is slightly more complex than below but I''ll give a simple > example to > describe the problem. > > There is a ''book'' table. A user can search for books by typing keywords > for book title and author name in a form. For example: show all books > that include the word ''peace'' in the title. The search results needs to > be paginated. > > # controller will look roughly like this > > def search_results > > title = params[:search][:title] > authorname = params[:search][:authorname] > > # form the sql query > sql = ''select * from books... where title =... and author_id=... " > > # create paginator and results. I''ll be using a custom pagination here > since it''s a find_by_sql. > # I know how to do this, the problem is not here... > @book_pages, @books = ... > > end > > now, the view includes first page of results, the pagination links with > page number in the url and all... the problem is that when clicking on > them (for example clicking on ''next page'') will never work since it > doesn''t include the request parameter of the book anymore. There is no > longer params[:search][:title] and params[:search][:authorname]. so > clicking on ''/book/search_results/page=2'' will fail saying that > params[:search][:title] is NIL... > > any idea how can i acheive this?The most common ways of doing it are hidden form variables or the session. The Scaffolding Extensions plugin [1] uses hidden form variables to paginate search results, if you want an example of how to do it. [1] http://wiki.rubyonrails.com/rails/pages/Scaffolding+Extensions+Plugin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Evans wrote:> The most common ways of doing it are hidden form variables or the > session. The Scaffolding Extensions plugin [1] uses hidden form > variables to paginate search results, if you want an example of how to > do it. > > [1] > http://wiki.rubyonrails.com/rails/pages/Scaffolding+Extensions+PluginThanks Jeremy! I completely forgot about the session as a way to store state... I''ll read about the scaffolding extensions to see if it''s a better way to do it. -- 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 -~----------~----~----~----~------~----~------~--~---