Hello all,
I'm trying to understand nested routes at the moment.
I generated these three models with the scaffold generator:
Because all models belong together I defined the following nested routes:Code Ruby:class Category < ActiveRecord::Base has_many :topics end class Topic < ActiveRecord::Base belongs_to :category has_many :posts end class Post < ActiveRecord::Base belongs_to :topic end
With these routes I have to change most of the generated views and controllers. For example instead of topic_path(params[:id]) it has to be category_topic_path(params[:category_id], params[:id]) and so on.Code Ruby:map.resources :categories do |categories| categories.resources :topics do |topics| topics.resources :posts end end
Is there any way to make this easier and less error prone?
I know it's not a good idea to have to deeply nested routes. But otherwise I don't know how to get all needed information. To create a topic for example I need the category_id ...
Thanks for any advices.
oerdec




Bookmarks