Folks, In a simple data-driven app, let''s assume we are modelling a collection of Widgets. So we start with the scaffolding and have URLS like this /widget/new /widget/edit /widget/destroy /widget/list ... But in a multi-user app, each _user_ has a collection of Widgets, so class Widget < ActiveRecord::Base belongs_to :user end What kind of URLs do we go for now, e.g. for a "new widget" screen? a) /widget/new # new widget for current user from session b) /user/new_widget # ditto c) /widget/new/14 # new widget for user #14 d) /user/14/new_widget # ditto e) Something else I''m sure there must be a best practice for this. Any hints? Thanks, Gavin
Gavin, have a look at the login controller http://wiki.rubyonrails.com/rails/show/LoginGenerator.You can either store your entire user model in the session (see the bit about model :user in application.rb in README_LOGIN) or just the id, and look it up when you need to. HTH, Chris On Apr 6, 2005 12:39 AM, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> Folks, > > In a simple data-driven app, let''s assume we are modelling a > collection of Widgets. So we start with the scaffolding and have URLS > like this > > /widget/new > /widget/edit > /widget/destroy > /widget/list > ... > > But in a multi-user app, each _user_ has a collection of Widgets, so > > class Widget < ActiveRecord::Base > belongs_to :user > end > > What kind of URLs do we go for now, e.g. for a "new widget" screen? > > a) /widget/new # new widget for current user from session > > b) /user/new_widget # ditto > > c) /widget/new/14 # new widget for user #14 > > d) /user/14/new_widget # ditto > > e) Something else > > I''m sure there must be a best practice for this. Any hints? > > Thanks, > Gavin > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Apr 5, 2005 6:39 PM, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> Folks, > > In a simple data-driven app, let''s assume we are modelling a > collection of Widgets. So we start with the scaffolding and have URLS > like this > > /widget/new > /widget/edit > /widget/destroy > /widget/list > ... > > But in a multi-user app, each _user_ has a collection of Widgets, so > > class Widget < ActiveRecord::Base > belongs_to :user > end > > What kind of URLs do we go for now, e.g. for a "new widget" screen? > > a) /widget/new # new widget for current user from session > > b) /user/new_widget # ditto > > c) /widget/new/14 # new widget for user #14 > > d) /user/14/new_widget # ditto > > e) Something else > > I''m sure there must be a best practice for this. Any hints?I think it''s personal preference. However, I like this scheme: /user/widgets (lists user''s widgets) /user/widgets/new (new widget for user) /user/my_widget_name (shows widget that belongs to user) /user/my_widget_name/edit (edits said widget) I suppose it depends on what other widgets you have. You can get away with /user/my_widget_name, but if you have multipel types of widgets, you may need /user/widget/my_widget_name and /user/otherwidgetmodel/other_widget_name. -- rick http://techno-weenie.net
I''m using the LoginGenerator, as it happens. The way I have it now, my WidgetContoller has "before_filter :login_required", so the "list" and "new" actions can assume there''s a user logged in, and be tailored to that user. So I''m going with /widget/new # tailored for the logged in user /widget/list # ditto Thanks for the comments, Chris and Rick. Gavin On Wednesday, April 6, 2005, 9:52:34 AM, Chris wrote:> Gavin, have a look at the login controller > http://wiki.rubyonrails.com/rails/show/LoginGenerator.You can either > store your entire user model in the session (see the bit about model > :user in application.rb in README_LOGIN) or just the id, and look it > up when you need to.> HTH,> Chris> On Apr 6, 2005 12:39 AM, Gavin Sinclair > <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote: >> Folks, >> >> In a simple data-driven app, let''s assume we are modelling a >> collection of Widgets. So we start with the scaffolding and have URLS >> like this >> >> /widget/new >> /widget/edit >> /widget/destroy >> /widget/list >> ... >> >> But in a multi-user app, each _user_ has a collection of Widgets, so >> >> class Widget < ActiveRecord::Base >> belongs_to :user >> end >> >> What kind of URLs do we go for now, e.g. for a "new widget" screen? >> >> a) /widget/new # new widget for current user from session >> >> b) /user/new_widget # ditto >> >> c) /widget/new/14 # new widget for user #14 >> >> d) /user/14/new_widget # ditto >> >> e) Something else >> >> I''m sure there must be a best practice for this. Any hints? >> >> Thanks, >> Gavin >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >>
On Apr 5, 2005 7:35 PM, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> I''m using the LoginGenerator, as it happens. The way I have it now, > my WidgetContoller has "before_filter :login_required", so the "list" > and "new" actions can assume there''s a user logged in, and be tailored > to that user. > > So I''m going with > > /widget/new # tailored for the logged in user > /widget/list # dittoThe only issue with that URL scheme is when you want to view someone else''s widgets (assuming this is a public app). If not, then nevermind :) -- rick http://techno-weenie.net
On Wednesday, April 6, 2005, 10:58:27 AM, Rick wrote:> On Apr 5, 2005 7:35 PM, Gavin Sinclair > <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote: >> I''m using the LoginGenerator, as it happens. The way I have it now, >> my WidgetContoller has "before_filter :login_required", so the "list" >> and "new" actions can assume there''s a user logged in, and be tailored >> to that user. >> >> So I''m going with >> >> /widget/new # tailored for the logged in user >> /widget/list # ditto> The only issue with that URL scheme is when you want to view someone > else''s widgets (assuming this is a public app). If not, then > nevermind :)OIC. Oh well, I''ll cross that bridge when I come to it.... and if/when I do, I''ll keep your /user/widget/my_widget_name scheme in mind. Gavin
Could you possibly let us know how you do it? I am very interested in this as well. -Thanks Shalev On Apr 5, 2005 9:08 PM, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> On Wednesday, April 6, 2005, 10:58:27 AM, Rick wrote: > > > On Apr 5, 2005 7:35 PM, Gavin Sinclair > > <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote: > >> I''m using the LoginGenerator, as it happens. The way I have it now, > >> my WidgetContoller has "before_filter :login_required", so the "list" > >> and "new" actions can assume there''s a user logged in, and be tailored > >> to that user. > >> > >> So I''m going with > >> > >> /widget/new # tailored for the logged in user > >> /widget/list # ditto > > > The only issue with that URL scheme is when you want to view someone > > else''s widgets (assuming this is a public app). If not, then > > nevermind :) > > OIC. Oh well, I''ll cross that bridge when I come to it.... and if/when I > do, I''ll keep your /user/widget/my_widget_name scheme in mind. > > Gavin > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >