In one of my pages I want to create some URLs that go to the same page, but tack on an extra parameter (column sorting stuff). How do I do that? I''ve tried link_to "Title", :sort => "title" and that''s pretty close...it keeps the controller name, but it doesn''t include one of the parameters. I''m using nested routes, so the URL should be http://site/companies/1/videos?sort=title but instead it''s just http://site/videos?sort=title Thanks for any help. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pat Maddox wrote:> In one of my pages I want to create some URLs that go to the same > page, but tack on an extra parameter (column sorting stuff). How do I > do that? > > I''ve tried > link_to "Title", :sort => "title" > > and that''s pretty close...it keeps the controller name, but it doesn''t > include one of the parameters. I''m using nested routes, so the URL > should be > http://site/companies/1/videos?sort=title > > but instead it''s just > http://site/videos?sort=title > > Thanks for any help. > > PatYour best bet is to just used the named route for the page your are on. videos_path(:company => @company, :sort => ''title'') -- 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 -~----------~----~----~----~------~----~------~--~---
Andy Delcambre
2007-Apr-09 22:13 UTC
Re: How do I use link_to with all the current options?
On 4/9/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In one of my pages I want to create some URLs that go to the same > page, but tack on an extra parameter (column sorting stuff). How do I > do that? > > I''ve tried > link_to "Title", :sort => "title" > > and that''s pretty close...it keeps the controller name, but it doesn''t > include one of the parameters. I''m using nested routes, so the URL > should be > http://site/companies/1/videos?sort=title > > but instead it''s just > http://site/videos?sort=title > > Thanks for any help. > > Pat >You will definitely need an :id as well, like: link_to "Title", :sort => "title", :id => 1 Without knowing how your controllers/actions are set up it is hard to say whether you need any other options. Something like: link_to "Title", :sort => "title", :id => 1, :controller => "companies" or something might be good, it should basically be like what your route looks like. Also take a look at named routes for this kind of thing as well. http://api.rubyonrails.org/classes/ActionController/Routing.html - Andy Delcambre --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4/9/07, Andy Delcambre <adelcambre-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 4/9/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > In one of my pages I want to create some URLs that go to the same > > page, but tack on an extra parameter (column sorting stuff). How do I > > do that? > > > > I''ve tried > > link_to "Title", :sort => "title" > > > > and that''s pretty close...it keeps the controller name, but it doesn''t > > include one of the parameters. I''m using nested routes, so the URL > > should be > > http://site/companies/1/videos?sort=title > > > > but instead it''s just > > http://site/videos?sort=title > > > > Thanks for any help. > > > > Pat > > > > You will definitely need an :id as well, like: > link_to "Title", :sort => "title", :id => 1 > > Without knowing how your controllers/actions are set up it is hard to > say whether you need any other options. Something like: > link_to "Title", :sort => "title", :id => 1, :controller => "companies"No, I want to keep the EXISTING url options on the page. So say for example, I''ve gone to http://site/companies/1/videos now I want to generate that exact same URL but add an extra parameter. I want to do this without explicitly setting the controller, action, IDs, etc. This is a template that we use in a lot of places, and now we want to add sorting. So basically I just want to merge the current url options with another parameter. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pat Maddox wrote:> > No, I want to keep the EXISTING url options on the page. So say for > example, I''ve gone to > > http://site/companies/1/videos > > now I want to generate that exact same URL but add an extra parameter. > I want to do this without explicitly setting the controller, action, > IDs, etc. This is a template that we use in a lot of places, and now > we want to add sorting. So basically I just want to merge the current > url options with another parameter. >Try link_to "Title", :overwrite_params => { :sort => ''title'' } I know the :overwrite_params option is valid with url_for() and link_to() relies on the method so it should work, in theory. -- Long http://MeandmyCity.com/ - Find your way http://edgesoft.ca/blog/read/2 - No-Cookie Session Support 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?hl=en -~----------~----~----~----~------~----~------~--~---
Pat Maddox wrote:> In one of my pages I want to create some URLs that go to the same > page, but tack on an extra parameter (column sorting stuff). How do I > do that? > > I''ve tried > link_to "Title", :sort => "title" > > and that''s pretty close...it keeps the controller name, but it doesn''t > include one of the parameters. I''m using nested routes, so the URL > should be > http://site/companies/1/videos?sort=title > > but instead it''s just > http://site/videos?sort=title > > Thanks for any help. > > Pat > > > > >I believe you may need to explicitly include the controller, action etc. Are you using RESTful routes? If you are, you''re probably looking at something like link_to videos_path(:company_id => 1, :sort =>"title"). I think (coffee not kicked in yet). Hope this helps Chris --------------------------------------- http://www.autopendium.co.uk stuff about old cars --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
See http://api.rubyonrails.com/classes/ActionController/Base.html#M000262 "If you explicitly want to create a URL that''s almost the same as the current URL, you can do so using the :overwrite_params options. Say for your posts you have different views for showing and printing them. Then, in the show view, you get the URL for the print view like this url_for :overwrite_params => { :action => ''print'' } This takes the current URL as is and only exchanges the action. In contrast, url_for :action => ''print'' would have slashed-off the path components after the changed action. Chad On Apr 9, 5:47 pm, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In one of my pages I want to create some URLs that go to the same > page, but tack on an extra parameter (column sorting stuff). How do I > do that? > > I''ve tried > link_to "Title", :sort => "title" > > and that''s pretty close...it keeps the controller name, but it doesn''t > include one of the parameters. I''m using nested routes, so the URL > should be > http://site/companies/1/videos?sort=title > > but instead it''s just > http://site/videos?sort=title > > Thanks for any help. > > Pat--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Apr-10 16:27 UTC
Re: How do I use link_to with all the current options?
Wow. I''m really thankful to you kittens for posting about this. What are the chances that I''d need something like this on my app this morning?! Apparently 100%. Thanks a ton! RSL On 4/10/07, Chad <matrix9180-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > See http://api.rubyonrails.com/classes/ActionController/Base.html#M000262 > > "If you explicitly want to create a URL that''s almost the same as the > current URL, you can do so using the :overwrite_params options. Say > for your posts you have different views for showing and printing them. > Then, in the show view, you get the URL for the print view like this > > url_for :overwrite_params => { :action => ''print'' } > > This takes the current URL as is and only exchanges the action. In > contrast, url_for :action => ''print'' would have slashed-off the path > components after the changed action. > > Chad > > On Apr 9, 5:47 pm, "Pat Maddox" <perg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > In one of my pages I want to create some URLs that go to the same > > page, but tack on an extra parameter (column sorting stuff). How do I > > do that? > > > > I''ve tried > > link_to "Title", :sort => "title" > > > > and that''s pretty close...it keeps the controller name, but it doesn''t > > include one of the parameters. I''m using nested routes, so the URL > > should be > > http://site/companies/1/videos?sort=title > > > > but instead it''s just > > http://site/videos?sort=title > > > > Thanks for any help. > > > > Pat > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4/10/07, Chad <matrix9180-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > See http://api.rubyonrails.com/classes/ActionController/Base.html#M000262 > > "If you explicitly want to create a URL that''s almost the same as the > current URL, you can do so using the :overwrite_params options. Say > for your posts you have different views for showing and printing them. > Then, in the show view, you get the URL for the print view like this > > url_for :overwrite_params => { :action => ''print'' } > > This takes the current URL as is and only exchanges the action. In > contrast, url_for :action => ''print'' would have slashed-off the path > components after the changed action. > > ChadHey Chad, thanks for the helpful response. Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---