Newbie with nested resources on rails 2.0

Hi,

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

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/[rest stuff] or
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 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

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
[email protected]

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
[email protected]

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

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:

On Dec 16, 2007 4:25 AM, Graham Seaman
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs