Hello, My controllers: - ForumsController - Forum::TopicsController - Forum::Topic::PostsController Resources: map.resources :forums do |forums| forums.resources :topics, :controller => "forum/topics" do |topics| topics.resources :posts, :controller => "forum/topic/posts" end end Is it a good design? Problem is that only way to get a post path is to call: forum_topic_post_path(post.topic.forum, post.topic, post) --~--~---------~--~----~------------~-------~--~----~ 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 Thu, Jan 15, 2009 at 3:28 PM, Dmitrij Smalko <dsmalko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > My controllers: > - ForumsController > - Forum::TopicsController > - Forum::Topic::PostsController > > Resources: > > map.resources :forums do |forums| > forums.resources :topics, :controller => "forum/topics" do |topics| > topics.resources :posts, :controller => "forum/topic/posts" > end > end > > Is it a good design? Problem is that only way to get a post path is to > call: > > forum_topic_post_path(post.topic.forum, post.topic, post) > > >There''s no need to have namespaces in your controllers - ForumsController - Forum::TopicsController - Forum::Topic::PostsController could be ForumsController TopicsController PostsController and then your resources can be: map.resources :forums do |forums| forums.resources :topics do |topics| topics.resources :posts end end it will still give you long urls like /forums/1/topics/1/posts/1 I''ve done some changes to get slightly shorter urls like this: map.resources :forums, :as => ''f'' do |forums| forums.resources :topics, :as => ''t'' do |topics| topics.resources :posts, :as ''p'' end end which then makes ther urls /f/1/t/1/p/1 and then if you use to_param in your models, you can get /f/1-my-forum/t/1-my-topic/p/1-my-post The to_param is done in the model class Forum < ActiveRecord::Base def to_param "#{id}-#{name.downcase.gsub(/[^0-9a-z]+/, ''-'')" end end -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok. But what if i will have following models: Video, Audio, Video::Playlist, Audio::Playlist and resouces: video -> has_many -> video/playlists audio -> has_many -> audio/playlists On 15 янв, 17:22, "Andrew Timberlake" <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> wrote:> On Thu, Jan 15, 2009 at 3:28 PM, Dmitrij Smalko <dsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, > > > My controllers: > > - ForumsController > > - Forum::TopicsController > > - Forum::Topic::PostsController > > > Resources: > > > map.resources :forums do |forums| > > forums.resources :topics, :controller => "forum/topics" do |topics| > > topics.resources :posts, :controller => "forum/topic/posts" > > end > > end > > > Is it a good design? Problem is that only way to get a post path is to > > call: > > > forum_topic_post_path(post.topic.forum, post.topic, post) > > There''s no need to have namespaces in your controllers > - ForumsController > - Forum::TopicsController > - Forum::Topic::PostsController > > could be > > ForumsController > TopicsController > PostsController > > and then your resources can be: > > map.resources :forums do |forums| > forums.resources :topics do |topics| > topics.resources :posts > end > end > > it will still give you long urls like /forums/1/topics/1/posts/1 > > I''ve done some changes to get slightly shorter urls like this: > > map.resources :forums, :as => ''f'' do |forums| > forums.resources :topics, :as => ''t'' do |topics| > topics.resources :posts, :as ''p'' > end > end > > which then makes ther urls /f/1/t/1/p/1 and then if you use to_param in your > models, you can get /f/1-my-forum/t/1-my-topic/p/1-my-post > > The to_param is done in the model > > class Forum < ActiveRecord::Base > def to_param > "#{id}-#{name.downcase.gsub(/[^0-9a-z]+/, ''-'')" > end > end > > -- > Andrew Timberlakehttp://ramblingsonrails.comhttp://www.linkedin.com/in/andrewtimberlake > > "I have never let my schooling interfere with my education" - Mark Twain--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/1/15 Dmitrij Smalko <dsmalko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > Ok. But what if i will have following models: > > Video, Audio, Video::Playlist, Audio::Playlist > > and resouces: > > video -> has_many -> video/playlists > audio -> has_many -> audio/playlistsI would probably make a single playlist model/controller that could deal with both audio and video Your way isn''t wrong, I was just suggesting another way -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So if you have BlogPost, ForumPost, FooPost, BarPost, etc. you suggest make a single controller? On 15 янв, 18:12, "Andrew Timberlake" <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> wrote:> 2009/1/15 Dmitrij Smalko <dsma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > Ok. But what if i will have following models: > > > Video, Audio, Video::Playlist, Audio::Playlist > > > and resouces: > > > video -> has_many -> video/playlists > > audio -> has_many -> audio/playlists > > I would probably make a single playlist model/controller that could deal > with both audio and video > > Your way isn''t wrong, I was just suggesting another way > > -- > Andrew Timberlakehttp://ramblingsonrails.comhttp://www.linkedin.com/in/andrewtimberlake > > "I have never let my schooling interfere with my education" - Mark Twain--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/1/16 Dmitrij Smalko <dsmalko@gmail.com>> > So if you have BlogPost, ForumPost, FooPost, BarPost, etc. you suggest > make a single controller? >Not a definitive 'yes' but in some cases it can work especially if the playlist has exactly the same functionality but is working on more than one type of model.> > On 15 янв, 18:12, "Andrew Timberlake" <and...@andrewtimberlake.com> > wrote: > > 2009/1/15 Dmitrij Smalko <dsma...@gmail.com> > > > > > > > > > Ok. But what if i will have following models: > > > > > Video, Audio, Video::Playlist, Audio::Playlist > > > > > and resouces: > > > > > video -> has_many -> video/playlists > > > audio -> has_many -> audio/playlists > > > > I would probably make a single playlist model/controller that could deal > > with both audio and video > > > > Your way isn't wrong, I was just suggesting another way > > > > -- > > Andrew Timberlakehttp://ramblingsonrails.comhttp:// > www.linkedin.com/in/andrewtimberlake > > > > "I have never let my schooling interfere with my education" - Mark Twain > > >-- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---