#19 Where Administration Goes
Apr 16, 2007 | 5 minutes | Administration
This is the first part of a three part series on building an administration system. Many developers choose to separate it completely from the public side of the site by placing it into an admin subdirectory. This episode will show you an alternative and often better solution.
This approach is pretty useful, but won't it complicate caching down the line?
This is just what I was looking for in a simple admin system. I'd already installed the RESTful Authentication plugin, but I'll probably pull it out and replace it with your simple system as shown in RailsCast #21 (http://railscasts.com/episodes/21). I only need to Admin it, not have personalized users. I saw hints of this in the PeepCode on Caching (http://www.peepcode.com/products/page-action-and-fragment-caching)
True, it can make caching a little more difficult. A solution that I like is to create an "admin" subdomain for the site (admin.example.com) then just have the "admin?" method return true for this subdomain. This way you can easily cache pages without this subdomain.
Hi, I'm building a very small site with two models. I'm just going to update it myself so the approach with script/generate scaffold episodes 'admin/episodes' sounds like a fast and easy way to solve it. Now to my question: How do I do the admin page with the links to the two scaffolds. If I have a admin controller it looks for actions in that controller, and if I don't have a admin controller I don't know how/where to make the /admin page...
Thanks in advance!
...I've also tried routing.
map.admin_project 'admin/projects', :controller => 'projects'
But I end up with a error:
NameError in ProjectsController#index
uninitialized constant ProjectsController
@Alfred, you can prefix the controller name with a forward slash so it goes to the root controller, not the one in the admin module:
link_to 'Projects', :controller => '/projects'
If that doesn't answer your question, I encourage you to post it on railsforum.com.
In your podcast you use the function edit_episode_path(episode). What does this function link to and how does it work?
@Justin, this method was generated from a named route which was generated by map.resources in the routes.rb file. I talk more about this in another episode:
Hi, I am very green. I know html and a little ruby and a little rails. I love how you set up authentication and editing on your site.
Previously I had followed a ROR tutorial to set up a blog with scaffolding but I couldn't make the next step to authentication.
I have watched episodes 19, 20, & 21 and now I want to follow your model of creating an index and referring to it in the controller.
I tried coping your code, but swapping "episode" for "post", which is what my entries are called. I came up with some missing method errors.
I know that I need to learn some more before I can make this work how I want to - can you point me in the right direction?
I'm guessing you're getting a no method error because I use named routes. If you take a look at the end of episode 21 (IIRC) I show the routes.rb file. Make sure to mimic this so you have the named routes.
If you still can't get it to work, I recommend posting this at railsforum.com along with the stack trace.
Thanks for the help. It wasn't the routes that were getting me. I had some syntax problems and a general lack of understanding of MVC - but I'm on the right track now.
Your tutorials are great. Thanks for the help.
Hi, I am very green on Rails yet. Could someone explain what is the issue with this approach and caching?
Ryan, great job!!
This is an interesting way of doing it - but there is a reason why this should NOT be done as a general way of implementing admin interface.
The reason is should you ever want to update your view (css, html etc) you may break down your site. Thus you will break your admin.
If - on the other hand your admin features are separated (i.e. admin/episodes, thus having a different view) - then you will always be able to alter/admin the site regardless of your view working or not.
Just my 5c
Of course, the necessity of being able to administrate a broken site is debatable.... Also, why would you publish your broken site?
Great videos guys!
One problem, I tried to:
script/generate scaffold existingmodel 'admin/existingmodel'
but I get
The name 'existingmodelHelper' is either already used in your application or reserved by Ruby on Rails.
Please choose an alternative and run this generator again.
But then if we do it the first time like mentionned, it doesn't make sens, does it?
Since I'm using flex also, the edit and destroy way doesn't seem to be a good approach...?
(btw I'm learning)
Just a quick clarification on page caching with an 'admin' sub domain. How do you conditionally cache or not cache the pages based on the subdomain? Do you use mod_rewrite rules to pass the request through to the app for all 'admin.foo.bar' requests?
A revised version of this episode would come in handy!
+1 for all three of these!
+1, and maybe a button to ask for a revised version ;-)