So I have a routing problem I''m running into. I have a model called Film, and each Film belongs to categories, which are being store in the DB as a serialized array in the category column. The films_controller is working right now with index, new, edit, delete actions. All is well using the default rails routing scheme. What I want to do is keep the films_controller as close to as it is now, but allow the user to view films by category using a url like this /admin/films/:category/:action/:id without loosing the ability to manage all films using urls like this: /admin/films/:action/:id I''ve tried setting up a route like this, both before and after the default rails routes: map.admin_films ''admin/films/:category/:action/:id'', :controller => ''admin/films'' When I place it before the default rails routes I get the category pages working, but the global actions (/admin/films/edit/1) error out with the following error: ''No action responded to 1'' When I place it after the default rails routes the category pages don''t work and I get the following error: ''No action responded to narrative_features'' (narrative_features being on of the categories films can belong to) Any help is appreciated. -- 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 -~----------~----~----~----~------~----~------~--~---
What you first want to do is to create a separate categories model and probably have an habtm relationship between films and categories (a film can have many categories and a a category can have many films). You should (generally) not do things like serialized arrays in database columns for things that are logical entities in your model. Basically, this is not a "normalized" database. For example, if you delete the last film that was part of the category "Western", you would no longer have "Western" as a category. Paul On Fri, 2008-02-22 at 01:45 +0100, Adam Duro wrote:> So I have a routing problem I''m running into. > > I have a model called Film, and each Film belongs to categories, which > are being store in the DB as a serialized array in the category column. > > The films_controller is working right now with index, new, edit, delete > actions. All is well using the default rails routing scheme. > > What I want to do is keep the films_controller as close to as it is now, > but allow the user to view films by category using a url like this > > /admin/films/:category/:action/:id > > without loosing the ability to manage all films using urls like this: > > /admin/films/:action/:id > > I''ve tried setting up a route like this, both before and after the > default rails routes: > > map.admin_films ''admin/films/:category/:action/:id'', :controller => > ''admin/films'' > > When I place it before the default rails routes I get the category pages > working, but the global actions (/admin/films/edit/1) error out with the > following error: > > ''No action responded to 1'' > > When I place it after the default rails routes the category pages don''t > work and I get the following error: > > ''No action responded to narrative_features'' > > (narrative_features being on of the categories films can belong to) > > Any help is appreciated.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh, and as far as the issue regarding routes, you might need to use regular expressions to help defined "Pretty URLs" http://api.rubyonrails.org/classes/ActionController/Routing.html On Thu, 2008-02-21 at 20:59 -0500, Paul Hoehne wrote:> What you first want to do is to create a separate categories model and > probably have an habtm relationship between films and categories (a film > can have many categories and a a category can have many films). You > should (generally) not do things like serialized arrays in database > columns for things that are logical entities in your model. Basically, > this is not a "normalized" database. > > For example, if you delete the last film that was part of the category > "Western", you would no longer have "Western" as a category. > > Paul > > On Fri, 2008-02-22 at 01:45 +0100, Adam Duro wrote: > > So I have a routing problem I''m running into. > > > > I have a model called Film, and each Film belongs to categories, which > > are being store in the DB as a serialized array in the category column. > > > > The films_controller is working right now with index, new, edit, delete > > actions. All is well using the default rails routing scheme. > > > > What I want to do is keep the films_controller as close to as it is now, > > but allow the user to view films by category using a url like this > > > > /admin/films/:category/:action/:id > > > > without loosing the ability to manage all films using urls like this: > > > > /admin/films/:action/:id > > > > I''ve tried setting up a route like this, both before and after the > > default rails routes: > > > > map.admin_films ''admin/films/:category/:action/:id'', :controller => > > ''admin/films'' > > > > When I place it before the default rails routes I get the category pages > > working, but the global actions (/admin/films/edit/1) error out with the > > following error: > > > > ''No action responded to 1'' > > > > When I place it after the default rails routes the category pages don''t > > work and I get the following error: > > > > ''No action responded to narrative_features'' > > > > (narrative_features being on of the categories films can belong to) > > > > Any help is appreciated. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul Hoehne wrote:> What you first want to do is to create a separate categories model and > probably have an habtm relationship between films and categories (a film > can have many categories and a a category can have many films). You > should (generally) not do things like serialized arrays in database > columns for things that are logical entities in your model. Basically, > this is not a "normalized" database. > > For example, if you delete the last film that was part of the category > "Western", you would no longer have "Western" as a category. > > PaulI tottally hear ya. I did this knowing it was lazy development, and that I would have to rewrite it eventually. In regards to the routes. Will I use a regex that checks to make sure that the :category matches only the available categories? Not sure how that is going to solve my problem. Thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Routes.rb ----------- ActionController::Routing::Routes.draw do |map| map.namespace(:backend, :path_prefix => :admin) do |backend| backend.resources :accounts, :collection => { :list => :any } backend.resources :articles, :collection => { :list => :any } backend.resources :sessions end map.backend ''/admin'', :controller => ''backend/base'', :action => ''index'' map.activation ''/admin/accounts/ activate/:activation_code'', :controller => ''backend/ accounts'', :action=>''activate'' map.connect ''javascripts/:action.:format'', :controller => ''javascripts'' map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end ----------- Question: How does http://localhost:3000/admin automatically get turned into http://localhost:3000/admin/sessions/new ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
### Nevermind -- I figured it out. On Feb 26, 8:56 pm, SmallPaul <VerySmallP...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Routes.rb > ----------- > ActionController::Routing::Routes.draw do |map| > map.namespace(:backend, :path_prefix => :admin) do |backend| > backend.resources :accounts, :collection => { :list => :any } > backend.resources :articles, :collection => { :list => :any } > backend.resources :sessions > end > > map.backend ''/admin'', :controller => ''backend/base'', :action => > ''index'' > map.activation ''/admin/accounts/ > activate/:activation_code'', :controller => ''backend/ > accounts'', :action=>''activate'' > map.connect ''javascripts/:action.:format'', :controller => > ''javascripts'' > > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > end > ----------- > > Question: How does > http://localhost:3000/admin > automatically get turned into > http://localhost:3000/admin/sessions/new > ?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---