#19
Apr 16, 2007

Where Administration Goes

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.
Download (19.1 MB, 5:12)
alternative download for iPod & Apple TV (8.3 MB, 5:12)

16 comments

Nathan Apr 25, 2007 at 10:16

This approach is pretty useful, but won't it complicate caching down the line?


Don Parish Apr 25, 2007 at 19:50

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)


Ryan Bates Apr 30, 2007 at 10:18

@Nathan,

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.


Alfred Jun 12, 2007 at 12:06

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!


Alfred Jun 12, 2007 at 12:34

...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


Ryan Bates Jun 12, 2007 at 16:13

@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.


Justin Smestad Jul 12, 2007 at 08:37

In your podcast you use the function edit_episode_path(episode). What does this function link to and how does it work?


Ryan Bates Jul 12, 2007 at 08:53

@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:

http://railscasts.com/episodes/34


Tim Inman Aug 13, 2007 at 02:55

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?


Ryan Bates Aug 13, 2007 at 08:51

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.


Tim Inman Aug 15, 2007 at 15:58

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.


James Nov 21, 2007 at 21:04

Hi, I am very green on Rails yet. Could someone explain what is the issue with this approach and caching?

Thanks,

Ryan, great job!!


Andriyko Feb 22, 2008 at 14:17

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


kino May 23, 2008 at 01:54

The transcendental unity of apperception excludes the possibility of, in particular, the objects in space and time.


iioiooioo Jun 14, 2008 at 11:53

Of course, the necessity of being able to administrate a broken site is debatable.... Also, why would you publish your broken site?


railsnewb Jun 26, 2008 at 10:46

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...?

thanks
(btw I'm learning)

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(required)

subscribe:
sponsored by:
if you want to help:
required:
Get Quicktime Player