Hi group, I was wondering if anyone more experienced could help me to find a good pattern for two things: 1. How to group controllers. Example: We have an admin panel with: user_managment_controller.rb priv_managment_controller.rb widget_controller.rb User panel with: mystuff_controller.rb mytags_controller.rb profile_controller.rb And frontend with: widget_controller.rb etc... How do I group those controllers? Should I put them in subdirectories? Does rails support this automagically? and 2. I have a model/table Widget with fields a,b,c,etc. Lets say guest can edit fields a,b users: a,b,c,d moderators1: a,b,c,d,e,f,g moderators1: a,b,c,d,g,h,i admins: a-z How do I implement this? Can I create a model-class for each user-group? How do I make sure that certain fields cannot be edited (for example by Widget.update_attributes(params[:widget])? Thanks PS: Obviously I want to make it ADAP (as DRY as possible) :) -- Posted via http://www.ruby-forum.com/.
Hi there, On 4/28/06, Wiktor <iktorn@gmail.com> wrote:> > Hi group, > > I was wondering if anyone more experienced could help me to find a good > pattern for two things: > > 1. How to group controllers. Example: > We have an admin panel with: > user_managment_controller.rb > priv_managment_controller.rb > widget_controller.rb > User panel with: > mystuff_controller.rb > mytags_controller.rb > profile_controller.rb > And frontend with: > widget_controller.rb > etc... > > How do I group those controllers? Should I put them in subdirectories? > Does rails support this automagically?Yep, subdirectories are the way to go: ruby script/generate controller admin/user_management ruby script/generate controller user/mystuff etc... you can move your existing controllers to sub-directories, you just need to modify them slightly: class UserManagementController < ApplicationController becomes class Admin::UserManagementController < ApplicationController and> > 2. I have a model/table Widget with fields a,b,c,etc. > Lets say guest can edit fields a,b > users: a,b,c,d > moderators1: a,b,c,d,e,f,g > moderators1: a,b,c,d,g,h,i > admins: a-z > > How do I implement this? Can I create a model-class for each user-group? > How do I make sure that certain fields cannot be edited (for example by > Widget.update_attributes(params[:widget])? > > Thanks > > PS: Obviously I want to make it ADAP (as DRY as possible) :)That''s been done for you too. Check out http://perens.com/FreeSoftware/ModelSecurity/ -- Scott Becker Web Developer Electro Interactive Web: http://www.ElectroInteractive.com Blog: http://synthesis.sbecker.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060429/d7c74c15/attachment.html
Thanks Scott,> Yep, subdirectories are the way to go:Ok, and how do I use them in routes/link_to? :controller => ??? -- Posted via http://www.ruby-forum.com/.
if you guessed: :controller => ''admin/user_management'' or :controller => ''user/mystuff'' then you were absolutely right! :) -- Scott Becker Web Developer Electro Interactive, Inc. http://www.ElectroInteractive.com On 5/5/06, Wiktor <iktorn@gmail.com> wrote:> Thanks Scott, > > > Yep, subdirectories are the way to go: > > Ok, and how do I use them in routes/link_to? > > :controller => ??? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Scott Becker wrote:> if you guessed: > > :controller => ''admin/user_management'' > > or > > :controller => ''user/mystuff'' > > then you were absolutely right! :):) Thanks Scott... one more thing is there a way to do (the code below doesn''t work...): map.connect '':controller_without_module/:action/:id'', :controller => ''module/:controller_without_module'' I need it to: map.forum '':controller_without_module/:action/:id'', :controller => ''forum/:controller_without_module'', :requirements => { :subdomain => ''forum'' } -- Posted via http://www.ruby-forum.com/.