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

  2. Adam

    Robert Dober Guest

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

    Cheers
    Robert



    --
    http://ruby-smalltalk.blogspot.com/

    ---
    Whereof one cannot speak, thereof one must be silent.
    Ludwig Wittgenstein
     
    Robert Dober, May 21, 2008
    #2
    1. Advertising

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
    Replies:
    0
    Views:
    1,299
    =?Utf-8?B?Q3JhaWc=?=
    Apr 26, 2005
  2. Replies:
    1
    Views:
    499
    Andreas Wollschlaeger
    Oct 6, 2006
  3. fearg
    Replies:
    10
    Views:
    2,477
    Hendrik Eeckhaut
    Aug 8, 2011
  4. Replies:
    1
    Views:
    124
    Christopher Schneider
    Nov 26, 2006
  5. Joachim Reichel
    Replies:
    4
    Views:
    95
    Joachim Reichel
    Jun 9, 2007
Loading...

Share This Page