# Newbie with nested resources on rails 2.0

**URL:** <https://www.ruby-forum.com/t/newbie-with-nested-resources-on-rails-2-0/123266>\
**Category:** Rails\
**Created:** [December 15, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/newbie-with-nested-resources-on-rails-2-0/123266 "2007-12-15T18:06:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsiener](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gsiener](https://www.ruby-forum.com/u/gsiener)\
**Post date:** [December 15, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/newbie-with-nested-resources-on-rails-2-0/123266/1 "2007-12-15T18:06:28Z")

</div>

Hi,

I just started with rails, and thought it made sense to go with 2.0 (  
know this isn’t necessarily a majority opinion 😉

I have an application which will potentially be used for a number of  
towns, each one of which might be quite different. I’m just working on  
one, ‘mytown’, for now.

Each town has it’s own admin section.

So urls look like [http://domain/Mytown/](http://domain/Mytown/)[rest stuff] or  
[http://domain/Mytown/admin/](http://domain/Mytown/admin/)[rest stuff]

The top level (non-admin) bit is currently working ok, on mainly static  
files (just using some partials, layouts etc). I haven’t attempted  
anything really dynamic yet.

The simplest part of the admin section just manages a list of surnames.  
So, for the admin section, I used:

ruby script/generate scaffold mytown::admin::surnames surname:string  
prefix:string

[http://localhost:3000/mytown/admin/surnames](http://localhost:3000/mytown/admin/surnames) gets routed to the  
Mytown::Admin::SurnamesController ok, but throws an error:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil./

on the line

@mytown/admin\_surnames = Mytown::Admin::Surnames.find(:all)

The problem seems to be the slash in the variable name. If I change  
this, of course I then get ‘no such variable’ type errors all down the  
line.

So, my question is: am I trying to do something I really shouldn’t be  
with this kind of nesting, or should I carry on just manually changing  
stuff bit by bit till it works? I’ve been following the second approach  
so far, but it does feel like rails is something you have to fight at  
every step, which is surely a sign that I’m going badly wrong somewhere.

Anyone?

Thanks  
Graham

---

<div class="post-metadata">

**Author:** ![gsiener](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gsiener](https://www.ruby-forum.com/u/gsiener)\
**Post date:** [December 16, 2007, 1:49am UTC](https://www.ruby-forum.com/t/newbie-with-nested-resources-on-rails-2-0/123266/2 "2007-12-16T01:49:57Z")

</div>

Scaffold for admin parts of the app is a pain because you have to  
manually  
change all the routes used in the generated views.

I would create model, controller and views separately. Since it is  
easier.

On Dec 15, 2007 9:06 AM, Graham Seaman  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gsiener](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gsiener](https://www.ruby-forum.com/u/gsiener)\
**Post date:** [December 16, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/newbie-with-nested-resources-on-rails-2-0/123266/3 "2007-12-16T13:25:00Z")

</div>

Bala P. wrote:

> Scaffold for admin parts of the app is a pain because you have to  
> manually  
> change all the routes used in the generated views.
> 
> I would create model, controller and views separately. Since it is  
> easier.
> 
> On Dec 15, 2007 9:06 AM, Graham Seaman  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

That’s fine if you know what they should look like. But I’m new to this,  
and I don’t. I was hoping to use the scaffold-generated code to learn  
what a simple application should look like, then go from there. But if  
the scaffold output is buggy, how do you start? I’ve been trying to  
follow through the activeresource code to see if I can work things out.  
It seems to me from that that maybe the problem is that you can only  
have a single ‘prefix’, and the fact that I am trying to use two  
(/mytown/admin) is the cause of all the problems?

Graham

---

<div class="post-metadata">

**Author:** ![gsiener](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gsiener](https://www.ruby-forum.com/u/gsiener)\
**Post date:** [December 18, 2007, 12:25am UTC](https://www.ruby-forum.com/t/newbie-with-nested-resources-on-rails-2-0/123266/4 "2007-12-18T00:25:09Z")

</div>

I think your problem is due to nested resource. When you nest, the  
parent  
object must be loaded in a before filter before you can perform any CRUD  
operation on it. Check out the Rails 2.0 screencast:

> **[The First Rails 2.0 Screencast | AkitaOnRails.com](https://www.akitaonrails.com/2007/12/10/the-first-rails-2-0-screencast-english)**
>
> Update 2013: This screencast is obviously obsolete (this is Rails 2 and Rails is already at version 4). It’s maintained here for historical reasons...

On Dec 16, 2007 4:25 AM, Graham Seaman  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
