I have a view with data that needs to be sorted and/or filtered. Previously, I had a form that would POST the filters or sorting commnds to the page. This breaks in REST because the auto-created routes tell rails I want to create a new record. For instance, map.resources :assets creates this route: POST /assets/ {:controller=>"assets", :action=>"create"} but, of course, posting the filter-form to that location invokes the create action when I really just want to invoke the index action. I came up with this, but it seems a bit dodgy: map.assets_stats ''/assets/stats'', :controller => "assets", :action => "index" If I have 10 controllers that all need this functionality, it becomes fairly un-DRY... Is the only solution to change my forms to GET instead of POST? Got to be a better way.... Thanks, Ed --~--~---------~--~----~------------~-------~--~----~ 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 1/26/07, Ed Hickey <bassnode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a view with data that needs to be sorted and/or filtered. > Previously, I had a form that would POST the filters or sorting commnds to > the page. This breaks in REST because the auto-created routes tell rails I > want to create a new record. For instance, map.resources :assets creates > this route: > > POST /assets/ {:controller=>"assets", :action=>"create"} > > but, of course, posting the filter-form to that location invokes the create > action when I really just want to invoke the index action. I came up with > this, but it seems a bit dodgy: > > map.assets_stats ''/assets/stats'', :controller => "assets", :action => > "index" > > If I have 10 controllers that all need this functionality, it becomes fairly > un-DRY... > Is the only solution to change my forms to GET instead of POST? Got to be a > better way.... > > > Thanks, > Ed > > >Ed, Just add a sort action: map.resources :assets, :collection => { :sort => :post } Hope this helps. -- Zack Chandler http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
> map.resources :assets, :collection => { :sort => :post }With a little creativity, or Jamis Buck''s blog in your feed reader [1], you can bust off some with_options action: map.with_options :collection => { :sort => :post } do |sortable_map| sortable_map.resources :assets sortable_map.resources :articles end Course, that may break down if some of your resources modify :collection on their own. Another option if you have a bunch of identical resources is to do this: map.resources :assets, :articles, :collection => { :sort => :post } 1. http://weblog.jamisbuck.org/2007/1/24/object-with_options -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
Should have mentioned that I did try that approach (using :collection) but this is what gave me: POST /assets;sort/ {:controller=>"assets", :action=>"sort"} I want the action to be "index", not "sort" because the data is all displayed in the index view. I want to POST to the index view without rails routing me to the create action. ed On 1/26/07, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > map.resources :assets, :collection => { :sort => :post } > > With a little creativity, or Jamis Buck''s blog in your feed reader > [1], you can bust off some with_options action: > > map.with_options :collection => { :sort => :post } do |sortable_map| > sortable_map.resources :assets > sortable_map.resources :articles > end > > Course, that may break down if some of your resources modify > :collection on their own. Another option if you have a bunch of > identical resources is to do this: > > map.resources :assets, :articles, :collection => { :sort => :post } > > 1. http://weblog.jamisbuck.org/2007/1/24/object-with_options > > -- > Rick Olson > http://weblog.techno-weenie.net > http://mephistoblog.com > > > >-- Ed Hickey Developer Litmus Media 816-533-0409 ehickey-A4HEbNdjHgMmlAP/+Wk3EA@public.gmane.org A Member of Think Partnership, Inc www.ThinkPartnership.com Amex ticker symbol: THK --~--~---------~--~----~------------~-------~--~----~ 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 1/26/07, Ed Hickey <bassnode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a view with data that needs to be sorted and/or filtered. > Is the only solution to change my forms to GET instead of POST? Got to be a > better way....If you''re just sorting/filtering the data, I would think it makes a lot more sense for the request to be a GET. Why don''t you want to change it like that? Anyway, another option is to have some kind of Results or Query object. You POST to create on that object, and you could do whatever you want from there. Either just list the elements, save the query for later, etc. 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 1/26/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 1/26/07, Ed Hickey <bassnode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have a view with data that needs to be sorted and/or filtered. > > Is the only solution to change my forms to GET instead of POST? Got to > be a > > better way.... > > If you''re just sorting/filtering the data, I would think it makes a > lot more sense for the request to be a GET. Why don''t you want to > change it like that?I guess I don''t really, I was just adverse to cluttering up the URL with all the filtering variables :) I changed them form method to GET and it works as needed now. Thanks for the help, everyone. -- Ed --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---