Forum: Ruby on Rails Call for patterns...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wiktor -. (Guest)
on 2006-04-29 01:12
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) :)
Scott B. (Guest)
on 2006-05-03 21:09
(Received via mailing list)
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) :)



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
Wiktor -. (Guest)
on 2006-05-05 12:55
Thanks Scott,

> Yep, subdirectories are the way to go:

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

:controller => ???
Scott B. (Guest)
on 2006-05-09 05:17
(Received via mailing list)
if you guessed:

:controller => 'admin/user_management'

or

:controller => 'user/mystuff'

then you were absolutely right! :)


--
Scott B.
Web D.
Electro Interactive, Inc.
http://www.ElectroInteractive.com
Wiktor -. (Guest)
on 2006-05-16 20:06
Scott B. 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' }
This topic is locked and can not be replied to.