newbie: hierarchical object model with RoR

Discussion in 'Ruby' started by Adam, May 21, 2008.

  1. Adam

    Adam Guest

    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 =>@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.
    Adam, May 21, 2008
    1. Advertisements

  2. Robert Dober

    Robert Dober Guest

    You might want to post this to the RoR mailing list.



    Whereof one cannot speak, thereof one must be silent.
    Ludwig Wittgenstein
    Robert Dober, May 21, 2008
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q3JhaWc=?=

    display hierarchical diagram of object

    =?Utf-8?B?Q3JhaWc=?=, Apr 26, 2005, in forum: ASP .Net
    Apr 26, 2005
  2. Replies:
    Andreas Wollschlaeger
    Oct 6, 2006
  3. fearg
    Hendrik Eeckhaut
    Aug 8, 2011
  4. Replies:
    Christopher Schneider
    Nov 26, 2006
  5. Joachim Reichel
    Joachim Reichel
    Jun 9, 2007

Share This Page