newbie: hierarchical object model with RoR

A

Adam

I've read all the simple tutorials and decided to have a go at
building a slightly more complicated application. Unfortunately I
immediately came unstuck. I have three objects, for the sake of
argument they are author, series and book. An author has many series',
and a series has many books. By extension an author also has many
books through series'. This is all fine and groovy, however what I'd
like is to be able to create a new series for an author from the
author's "show" page (if that terminology makes sense, I couldn't
think of a better way to put it), and pass the author's id through so
that the user doesn't have to (and also _can't_) set the author id
manually. Obviously I'd like the same situation with books in series'.
I can't figure out how to do it. I'm almost there, but it's not quite
right and I keep getting errors that suggest to me that I don't have
access to an @Author at the time I'm trying to access it in my
controller. I have something like @author=Authors.find:)author_id)
followed by @series=Series.new:)author_id =>@author). I can't be
absolutely certain because I haven't got the code in front of me at
the moment, but that's the gist. I'm also trying to use RESTful urls,
but not getting very far with that either. I've set up the routes file
so that authors have many series' and series' have many books, and I
can access my books via http://myhost:3000/authors/1/books/1, but the
app doesn't see to use this convention internally, so if I click a
link within my author to take me to his books, I get http://myhost:3000/books/1,
rather than http://myhost:3000/authors/1/books/1.

I've found there's an awful lot of really, really simple tutorials out
there, and an awful lot of stuff that assumes you know roughly what
you're doing, but I can't find anything in between. Can anyone give me
a simple recipe to get these relationships set up the way I want? I'm
sure it's something ridiculously simple that I'm just completely
missing, but it's frustrating me now and rather than bang my head
against the wall for another evening I thought it was prudent to ask.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top