SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Nov 29, 2005, 11:51 #1
- Join Date
- May 2005
- Location
- Sweden
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Best way to "design" the controllers?
I'm about making a design for my page but before moving on I would like to here some opinions about how you deal with controllers.
Is it best to not have to many controllers?
My first idea was to have the following:
- admin_controller (for admin pages, limited access)
- public_controller (for public pages)
- authorize_controller (dealing with the login/logout stuff)
This seems clean and simple. The disadvantage with this solution is that the public and the admin controll might become big.
The advantage that I can see is that it easy to see which controller to updated when adding new features.
Is this a good way to build up the site? As it is now, the controllers are flexible.
The other way I have been thinking of is to have more specific controller, for example:
- admin_user
- admin_ news
And so on...
How do you do when you develop, and why?
-
Nov 29, 2005, 13:04 #2
You can group your controllers into modules, say Admin::UserController, which lives in app/controllers/admin/user_controller.rb
I think you should keep your controllers as small as possible. They should focus on a specific area of functionality, the basis of any good class design, and controllers are just classes.
-
Nov 29, 2005, 13:26 #3
- Join Date
- May 2005
- Location
- Sweden
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That seems like a good idea. I tried it earlier today but I couldn't find any way to access the page.
app/controllers/admin/user_controller.rb:
http://mypage/admin/user/
User is okey because it is a controller. The admin i different though because it is a folder. Do I need to have a admin controller that redirects the request to the folder admin in my controller folder?
-
Nov 29, 2005, 13:59 #4
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Do you get an error message?
http://mypage/admin/user/
Means that you load Admin::UserController.
Do you get any error messages?
I would implement this in another way. I would have one controller for users: UsersController which has several methods, some of them are public, others are admin-only. You can find more information here: http://manuals.rubyonrails.com/read/chapter/49#page142
-
Nov 29, 2005, 14:04 #5
- Join Date
- May 2005
- Location
- Sweden
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Interesting I will look on that too.
I get some kind of routing error. It's seems that it finds the controller but fails on loading it?
I try to access it by:
http://mypage/test/mytest
Test is not a controller it's a folder in my controller folder.
mytest is a controller in the folder test mentioned above.
LoadError in <controller not set>#<action not set>
Already loaded file './script/../config/../app/controllers/test/mytest_controller.rb' but 'MytestController' was not set, perhaps you need to rename './script/../config/../app/controllers/test/mytest_controller.rb'?
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
-
Nov 29, 2005, 15:00 #6
- Join Date
- May 2005
- Location
- Sweden
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No clue, or is it impossible to have folders in the controller folder?
Last edited by JoL; Nov 29, 2005 at 15:36.
-
Nov 29, 2005, 16:19 #7
What is the name of the class in mytest_controller.rb? It should be Test::MytestController.
-
Nov 29, 2005, 17:12 #8
- Join Date
- May 2005
- Location
- Sweden
- Posts
- 52
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, now it work just perfectly!
Bookmarks