I have a page that returns data and I need to let the user sort it. I have this: <% form_tag courses_path, :method => :get do -%> <%= select_tag :order, options_for_select(%w(date rating author)) %> <%= submit_tag "Order", :name => nil %> <% end -%> However, this erases any existing params in the url. For example, if the url is http://localhost:3000/pictures?tag=vacation then the form above will get http://localhost:3000/pictures?order=rating when I really want http://localhost:3000/pictures?tag=vacation&order=rating I tried this, but it doesn''t work. <% form_tag :url => {:overwrite_params => :order, :method => :get} do - %> <%= select_tag :order, options_for_select(%w(date rating author)) %> <%= submit_tag "Order", :name => nil %> <% end -%> This doesn''t work either: <%= select_tag :order, options_for_select(%w(date rating author)), :onchange => remote_function( :url => {:overwrite_params => { :order => "order.value" }}, :method => :get ) %> Can someone help? I''ve spent way too much time on this :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
One quick and easy way to preserve your params would be to create a hidden field in the form which takes its name and value from the param that you''d like to preserve. <% form_tag courses_path, :method => :get do -%> <%= select_tag :order, options_for_select(%w(date rating author)) %> <%= hidden_field_tag :tag, params[:tag] %> <%= submit_tag "Order", :name => nil %> <% end -%> Hope that helps, kb On Apr 26, 11:29 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a page that returns data and I need to let the user sort it. I > have this: > > <% form_tag courses_path, :method => :get do -%> > <%= select_tag :order, options_for_select(%w(date rating author)) %> > <%= submit_tag "Order", :name => nil %> > <% end -%> > > However, this erases any existing params in the url. For example, if > the url ishttp://localhost:3000/pictures?tag=vacationthen the form > above will gethttp://localhost:3000/pictures?order=ratingwhen I > really wanthttp://localhost:3000/pictures?tag=vacation&order=rating > > I tried this, but it doesn''t work. > > <% form_tag :url => {:overwrite_params => :order, :method => :get} do - > %> > <%= select_tag :order, options_for_select(%w(date rating author)) %> > <%= submit_tag "Order", :name => nil %> > <% end -%> > > This doesn''t work either: > > <%= select_tag :order, options_for_select(%w(date rating author)), > :onchange => remote_function( :url => > {:overwrite_params => { :order => "order.value" }}, > :method => :get ) %> > > Can someone help? I''ve spent way too much time on this :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
if possible, I''d like to use this as a last resort - I showed the tag param as an example, but I actually have a lot of params and it would be painful to create hidden fields for all of them. I''m surprised at how little I was able to find on this topic since I''ve seen so many websites that let users sort results using a simple drop down. Am I approaching this in a completely wrong way? thanks. On Apr 26, 11:43 am, Kyle Banker <kyleban...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> One quick and easy way to preserve your params would be to create a > hidden field in the form which takes its name and value from the param > that you''d like to preserve. > > <% form_tag courses_path, :method => :get do -%> > <%= select_tag :order, options_for_select(%w(date rating > author)) %> > <%= hidden_field_tag :tag, params[:tag] %> > <%= submit_tag "Order", :name => nil %> > <% end -%> > > Hope that helps, > > kb > > On Apr 26, 11:29 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a page that returns data and I need to let the user sort it. I > > have this: > > > <% form_tag courses_path, :method => :get do -%> > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > <%= submit_tag "Order", :name => nil %> > > <% end -%> > > > However, this erases any existing params in the url. For example, if > > the url ishttp://localhost:3000/pictures?tag=vacationthenthe form > > above will gethttp://localhost:3000/pictures?order=ratingwhenI > > really wanthttp://localhost:3000/pictures?tag=vacation&order=rating > > > I tried this, but it doesn''t work. > > > <% form_tag :url => {:overwrite_params => :order, :method => :get} do - > > %> > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > <%= submit_tag "Order", :name => nil %> > > <% end -%> > > > This doesn''t work either: > > > <%= select_tag :order, options_for_select(%w(date rating author)), > > :onchange => remote_function( :url => > > {:overwrite_params => { :order => "order.value" }}, > > :method => :get ) %> > > > Can someone help? I''ve spent way too much time on this :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In that case, you might want to write a custom helper, something like courses_path_with_params which will append the appropriate params to courses_path. I''d be equally interested to know if there''s a better way. On Apr 26, 11:51 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> if possible, I''d like to use this as a last resort - I showed the tag > param as an example, but I actually have a lot of params and it would > be painful to create hidden fields for all of them. > > I''m surprised at how little I was able to find on this topic since > I''ve seen so many websites that let users sort results using a simple > drop down. Am I approaching this in a completely wrong way? > > thanks. > > On Apr 26, 11:43 am, Kyle Banker <kyleban...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > One quick and easy way to preserve your params would be to create a > > hidden field in the form which takes its name and value from the param > > that you''d like to preserve. > > > <% form_tag courses_path, :method => :get do -%> > > <%= select_tag :order, options_for_select(%w(date rating > > author)) %> > > <%= hidden_field_tag :tag, params[:tag] %> > > <%= submit_tag "Order", :name => nil %> > > <% end -%> > > > Hope that helps, > > > kb > > > On Apr 26, 11:29 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a page that returns data and I need to let the user sort it. I > > > have this: > > > > <% form_tag courses_path, :method => :get do -%> > > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > > <%= submit_tag "Order", :name => nil %> > > > <% end -%> > > > > However, this erases any existing params in the url. For example, if > > > the url ishttp://localhost:3000/pictures?tag=vacationthentheform > > > above will gethttp://localhost:3000/pictures?order=ratingwhenI > > > really wanthttp://localhost:3000/pictures?tag=vacation&order=rating > > > > I tried this, but it doesn''t work. > > > > <% form_tag :url => {:overwrite_params => :order, :method => :get} do - > > > %> > > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > > <%= submit_tag "Order", :name => nil %> > > > <% end -%> > > > > This doesn''t work either: > > > > <%= select_tag :order, options_for_select(%w(date rating author)), > > > :onchange => remote_function( :url => > > > {:overwrite_params => { :order => "order.value" }}, > > > :method => :get ) %> > > > > Can someone help? I''ve spent way too much time on this :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ok. I think I''m getting close :) <%= select_tag :order, options_for_select(%w(date rating author)), { :onchange => remote_function( :url => request.request_uri, :method => :get, :with => ''Form.Element.serialize(this)'') } %> the "problem" with this is that now the order param gets repeated, for example http://site.com?tags=vacation&order=date&order=rating anyone know how to remove a param from a query string? On Apr 26, 12:20 pm, Kyle Banker <kyleban...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In that case, you might want to write a custom helper, something like > > courses_path_with_params > > which will append the appropriate params to courses_path. > > I''d be equally interested to know if there''s a better way. > > On Apr 26, 11:51 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > if possible, I''d like to use this as a last resort - I showed the tag > > param as an example, but I actually have a lot of params and it would > > be painful to create hidden fields for all of them. > > > I''m surprised at how little I was able to find on this topic since > > I''ve seen so many websites that let users sort results using a simple > > drop down. Am I approaching this in a completely wrong way? > > > thanks. > > > On Apr 26, 11:43 am, Kyle Banker <kyleban...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > One quick and easy way to preserve your params would be to create a > > > hidden field in the form which takes its name and value from the param > > > that you''d like to preserve. > > > > <% form_tag courses_path, :method => :get do -%> > > > <%= select_tag :order, options_for_select(%w(date rating > > > author)) %> > > > <%= hidden_field_tag :tag, params[:tag] %> > > > <%= submit_tag "Order", :name => nil %> > > > <% end -%> > > > > Hope that helps, > > > > kb > > > > On Apr 26, 11:29 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have a page that returns data and I need to let the user sort it. I > > > > have this: > > > > > <% form_tag courses_path, :method => :get do -%> > > > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > > > <%= submit_tag "Order", :name => nil %> > > > > <% end -%> > > > > > However, this erases any existing params in the url. For example, if > > > > the url ishttp://localhost:3000/pictures?tag=vacationthentheform > > > > above will gethttp://localhost:3000/pictures?order=ratingwhenI > > > > really wanthttp://localhost:3000/pictures?tag=vacation&order=rating > > > > > I tried this, but it doesn''t work. > > > > > <% form_tag :url => {:overwrite_params => :order, :method => :get} do - > > > > %> > > > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > > > <%= submit_tag "Order", :name => nil %> > > > > <% end -%> > > > > > This doesn''t work either: > > > > > <%= select_tag :order, options_for_select(%w(date rating author)), > > > > :onchange => remote_function( :url => > > > > {:overwrite_params => { :order => "order.value" }}, > > > > :method => :get ) %> > > > > > Can someone help? I''ve spent way too much time on this :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Perhaps you could somehow get :overwrite_params in there... -Kyle On Apr 27, 2:29 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ok. I think I''m getting close :) > > <%= select_tag :order, options_for_select(%w(date rating author)), > { :onchange => remote_function( :url => > request.request_uri, > :method => :get, > :with => > ''Form.Element.serialize(this)'') } %> > > the "problem" with this is that now the order param gets repeated, for > examplehttp://site.com?tags=vacation&order=date&order=rating > > anyone know how to remove a param from a query string? > > On Apr 26, 12:20 pm, Kyle Banker <kyleban...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > In that case, you might want to write a custom helper, something like > > > courses_path_with_params > > > which will append the appropriate params to courses_path. > > > I''d be equally interested to know if there''s a better way. > > > On Apr 26, 11:51 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > if possible, I''d like to use this as a last resort - I showed the tag > > > param as an example, but I actually have a lot of params and it would > > > be painful to create hidden fields for all of them. > > > > I''m surprised at how little I was able to find on this topic since > > > I''ve seen so many websites that let users sort results using a simple > > > drop down. Am I approaching this in a completely wrong way? > > > > thanks. > > > > On Apr 26, 11:43 am, Kyle Banker <kyleban...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > One quick and easy way to preserve your params would be to create a > > > > hidden field in the form which takes its name and value from the param > > > > that you''d like to preserve. > > > > > <% form_tag courses_path, :method => :get do -%> > > > > <%= select_tag :order, options_for_select(%w(date rating > > > > author)) %> > > > > <%= hidden_field_tag :tag, params[:tag] %> > > > > <%= submit_tag "Order", :name => nil %> > > > > <% end -%> > > > > > Hope that helps, > > > > > kb > > > > > On Apr 26, 11:29 am, vince <stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I have a page that returns data and I need to let the user sort it. I > > > > > have this: > > > > > > <% form_tag courses_path, :method => :get do -%> > > > > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > > > > <%= submit_tag "Order", :name => nil %> > > > > > <% end -%> > > > > > > However, this erases any existing params in the url. For example, if > > > > > the url ishttp://localhost:3000/pictures?tag=vacationthentheform > > > > > above will gethttp://localhost:3000/pictures?order=ratingwhenI > > > > > really wanthttp://localhost:3000/pictures?tag=vacation&order=rating > > > > > > I tried this, but it doesn''t work. > > > > > > <% form_tag :url => {:overwrite_params => :order, :method => :get} do - > > > > > %> > > > > > <%= select_tag :order, options_for_select(%w(date rating author)) %> > > > > > <%= submit_tag "Order", :name => nil %> > > > > > <% end -%> > > > > > > This doesn''t work either: > > > > > > <%= select_tag :order, options_for_select(%w(date rating author)), > > > > > :onchange => remote_function( :url => > > > > > {:overwrite_params => { :order => "order.value" }}, > > > > > :method => :get ) %> > > > > > > Can someone help? I''ve spent way too much time on this :)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---