Navjeet Chabbewal
2006-Jan-28 05:37 UTC
[Rails] how to pass search parameters to pagination links
I have a search page with a text_field as below <%= text_field ''program'', ''program_name'' %> After I perform the search in my controller I go to a search results view which shows search results and uses Rails pagination. Now how to pass the search paramters (i.e. params[:program][:program_name] in my controller) to the pagination links (next and previous) in my search results view so that the last search parameters are passed on to the search method in the controller that builds the next page. --Jeet -- Posted via http://www.ruby-forum.com/.
zbyte pepsi-hola
2006-Jan-28 06:29 UTC
[Rails] how to pass search parameters to pagination links
hmm, on a side note, if we didn''t want to keep on researching the db and rather cache the results in lets say the session variable, i suppose we would have to assign it an id and such, but ya, how do u pass variables onto the pagination link? On 1/28/06, Navjeet Chabbewal <navjeetc@gmail.com> wrote:> > I have a search page with a text_field as below > > <%= text_field ''program'', ''program_name'' %> > > After I perform the search in my controller I go to a search results > view which shows search results and uses Rails pagination. Now how to > pass the search paramters (i.e. params[:program][:program_name] in my > controller) to the pagination links (next and previous) in my search > results view so that the last search parameters are passed on to the > search method in the controller that builds the next page. > > > --Jeet > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20060128/38ec4c14/attachment.html
Nick Stuart
2006-Jan-28 14:41 UTC
[Rails] how to pass search parameters to pagination links
Easiest way would be to save the search term in your session and use when you construct the pages. Another way would be to generate your own page links and add on the search parameter to each on. -Nick On 1/28/06, Navjeet Chabbewal <navjeetc@gmail.com> wrote:> > I have a search page with a text_field as below > > <%= text_field ''program'', ''program_name'' %> > > After I perform the search in my controller I go to a search results > view which shows search results and uses Rails pagination. Now how to > pass the search paramters (i.e. params[:program][:program_name] in my > controller) to the pagination links (next and previous) in my search > results view so that the last search parameters are passed on to the > search method in the controller that builds the next page. > > > --Jeet > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20060128/763bcebc/attachment.html
zbyte pepsi-hola
2006-Jan-28 22:18 UTC
[Rails] how to pass search parameters to pagination links
Thing about storing it in your session though, it would be messed up if someone did more then one search. On 1/28/06, Nick Stuart <nicholas.stuart@gmail.com> wrote:> > Easiest way would be to save the search term in your session and use when > you construct the pages. Another way would be to generate your own page > links and add on the search parameter to each on. > > -Nick > > On 1/28/06, Navjeet Chabbewal <navjeetc@gmail.com> wrote: > > > > I have a search page with a text_field as below > > > > <%= text_field ''program'', ''program_name'' %> > > > > After I perform the search in my controller I go to a search results > > view which shows search results and uses Rails pagination. Now how to > > pass the search paramters (i.e. params[:program][:program_name] in my > > controller) to the pagination links (next and previous) in my search > > results view so that the last search parameters are passed on to the > > search method in the controller that builds the next page. > > > > > > --Jeet > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > 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 > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060128/ac69a7aa/attachment.html
Navjeet Chabbewal
2006-Jan-28 22:57 UTC
[Rails] Re: how to pass search parameters to pagination links
The issue is not the storage but how to send a hash to a link_to? zbyte pepsi-hola wrote:> Thing about storing it in your session though, it would be messed up if > someone did more then one search.-- Posted via http://www.ruby-forum.com/.
zbyte pepsi-hola
2006-Jan-29 06:44 UTC
[Rails] Re: how to pass search parameters to pagination links
or rather, pagination. I think it should be a feature in pagination (if it doesn''t already exist). After all, I shouldn''t rewrite some code that already exists.... On 1/28/06, Navjeet Chabbewal <navjeetc@gmail.com> wrote:> > The issue is not the storage but how to send a hash to a link_to? > > > zbyte pepsi-hola wrote: > > Thing about storing it in your session though, it would be messed up if > > someone did more then one search. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20060129/739bda16/attachment.html
Leah Cunningham
2006-Jan-29 21:30 UTC
[Rails] Re: how to pass search parameters to pagination links
Navjeet Chabbewal wrote:> I have a search page with a text_field as below > > <%= text_field ''program'', ''program_name'' %>If I understand the problem correctly, I can give an example of how I''ve been doing this sort of thing, but I''m not positive it''s correct: I have a params[:type] parameter that is passed into a search, so the controller method in the account controller looks like: <pre> def list_by_type @type = params[:type] @user_pages_by_type, @users_by_type = paginate :users, :conditions => ["U_Type = ?", @type], :per_page => 20 end </pre> And it could be called in an rhtml file like: <pre> <%= link_to "Retail Accounts", :controller => "account", :action => "list_by_type", :type => "R" %> </pre> In the list_by_type.rhtml file: <pre> <%= link_to ''Previous page'', { :page => @user_pages_by_type.current.previous, :type => @type } if @user_pages_by_type.current.previous %> <%= link_to ''Next page'', { :page => @user_pages_by_type.current.next, :type => @type } if @user_pages_by_type.current.next %> | Pages : <%= pagination_links(@user_pages_by_type, :params => {:type => @type}) %> </pre> -- Posted via http://www.ruby-forum.com/.
Leah Cunningham
2006-Jan-29 21:31 UTC
[Rails] Re: how to pass search parameters to pagination links
Navjeet Chabbewal wrote:> I have a search page with a text_field as below > > <%= text_field ''program'', ''program_name'' %>If I understand the problem correctly, I can give an example of how I''ve been doing this sort of thing, but I''m not positive it''s correct: I have a params[:type] parameter that is passed into a search, so the controller method in the account controller looks like: def list_by_type @type = params[:type] @user_pages_by_type, @users_by_type = paginate :users, :conditions => ["U_Type = ?", @type], :per_page => 20 end And it could be called in an rhtml file like: <%= link_to "Retail Accounts", :controller => "account", :action => "list_by_type", :type => "R" %> In the list_by_type.rhtml file: <%= link_to ''Previous page'', { :page => @user_pages_by_type.current.previous, :type => @type } if @user_pages_by_type.current.previous %> <%= link_to ''Next page'', { :page => @user_pages_by_type.current.next, :type => @type } if @user_pages_by_type.current.next %> | Pages : <%= pagination_links(@user_pages_by_type, :params => {:type => @type}) %> -- Posted via http://www.ruby-forum.com/.
Navjeet Chabbewal
2006-Jan-30 16:23 UTC
[Rails] Re: how to pass search parameters to pagination links
Leah, What if the params :type is not a simple string but a hash e.g. program[:name] as generated by ActionView helper text_field ''program'', ''name'' --Navjeet Leah Cunningham wrote:> Navjeet Chabbewal wrote: >> I have a search page with a text_field as below >> >> <%= text_field ''program'', ''program_name'' %> > > If I understand the problem correctly, I can give an example of how I''ve > been doing this sort of thing, but I''m not positive it''s correct: > > I have a params[:type] parameter that is passed into a search, so the > controller method in the account controller looks like: > > > def list_by_type > @type = params[:type] > @user_pages_by_type, @users_by_type = paginate :users, :conditions > => ["U_Type = ?", @type], :per_page => 20 > end > > And it could be called in an rhtml file like: > > <%= link_to "Retail Accounts", > :controller => "account", > :action => "list_by_type", > :type => "R" %> > > In the list_by_type.rhtml file: > > <%= link_to ''Previous page'', { :page => > @user_pages_by_type.current.previous, > :type => @type } if @user_pages_by_type.current.previous %> > <%= link_to ''Next page'', { :page => @user_pages_by_type.current.next, > :type => @type } if @user_pages_by_type.current.next %> > | Pages : <%= pagination_links(@user_pages_by_type, :params => {:type => @type}) %>-- Posted via http://www.ruby-forum.com/.