Call for patterns


#1

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

  1. 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) :slight_smile:


#2

Hi there,

On 4/28/06, Wiktor removed_email_address@domain.invalid wrote:

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

Widget.update_attributes(params[:widget])?

Thanks

PS: Obviously I want to make it ADAP (as DRY as possible) :slight_smile:

That’s been done for you too. Check out
http://perens.com/FreeSoftware/ModelSecurity/


Scott B.
Web D.
Electro Interactive
Web: http://www.ElectroInteractive.com
Blog: http://synthesis.sbecker.net


#3

Thanks Scott,

Yep, subdirectories are the way to go:

Ok, and how do I use them in routes/link_to?

:controller => ???


#4

Scott B. wrote:

if you guessed:

:controller => ‘admin/user_management’

or

:controller => ‘user/mystuff’

then you were absolutely right! :slight_smile:

:slight_smile: 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’ }


#5

if you guessed:

:controller => ‘admin/user_management’

or

:controller => ‘user/mystuff’

then you were absolutely right! :slight_smile:


Scott B.
Web D.
Electro Interactive, Inc.
http://www.ElectroInteractive.com