I''ll use my recipe example again. It would be nice if I could have my routes (I think) set up so that if somebody enters a a controller that doesn''t exist a database search runs and looks for the controller name as one of the categories (for example the user enters http://www.com/italian). This is an existing category in the database so it would likely then redirect to www.com/categories/italian (and from there the categories controller would handle things). Is this possible without violating any "rules"? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-May-11 20:13 UTC
Re: If controller doesn''t exist: search database for its name
On 11 May 2010 21:03, sso <strongsilentone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> if somebody enters a a controller that doesn''t exist a database search > runs and looks for the controller name > > Is this possible without violating any "rules"?You would probably be able to do something by catching 404 errors in your application controller and then punting them off to a method that tries to guess what the user meant. Google for "Rails 404" for a few methods to try. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-May-12 03:33 UTC
Re: If controller doesn''t exist: search database for its nam
Michael Pavling wrote:> On 11 May 2010 21:03, sso <strongsilentone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> if somebody enters a a controller that doesn''t exist a database search >> runs and looks for the controller name >> >> Is this possible without violating any "rules"? > > You would probably be able to do something by catching 404 errors in > your application controller and then punting them off to a method that > tries to guess what the user meant. Google for "Rails 404" for a few > methods to try.Actually, no 404 catching is necessary. All you need is a catchall route that sends ''/:category'' off to a search action. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bill Walton
2010-May-12 14:08 UTC
Re: If controller doesn''t exist: search database for its name
On Tue, May 11, 2010 at 3:03 PM, sso <strongsilentone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ll use my recipe example again. > It would be nice if I could have my routes (I think) set up so that if > somebody enters a a controller that doesn''t exist a database search > runs and looks for the controller name as one of the categories (for > example the user enters http://www.com/italian). This is an existing > category in the database so it would likely then redirect to > www.com/categories/italian (and from there the categories controller > would handle things). > > Is this possible without violating any "rules"? > >You can override method_missing. We used that approach at my last gig to grab userr-created content from a SharePoint site. HTH, Bill -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.