SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict DevilBear's Avatar
    Join Date
    Oct 2001
    Location
    Hades
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rails - working with more than one table at a time

    Hi folks,

    So rails makes it ridiculously easy to do things with a single table... but when things get the least bit complex, I'm getting lost...

    Got the relationships between the tables mapped out in the models, and that does help...

    But, for example, the scaffold templates utilize the table's "content_columns" only... so I need to go in and program in display code for the data held in other tables. And here's where the Ruby/Rails simplicity seems to get in my way.

    This is all it takes the scaffold to create the table headers:

    <% for column in Race.content_columns %>
    <th><%= column.human_name %></th>
    <% end %>

    Great... now is there a way to get it to draw from all the columns, not just the content_columns, automatically? That way I don't have to come in and update this template again if/when I make a change to the table?

    -DB

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use columns instead of content_columns.

  3. #3
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, try not to get hung up on the severe limitations of scaffolding - its only real purpose is in learning Rails and quickly prototyping/trying out new ideas. The more you get to know Rails the less useful it becomes. Its probably Rails' most overrated feature.

  4. #4
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Luke Redpath
    Also, try not to get hung up on the severe limitations of scaffolding - its only real purpose is in learning Rails and quickly prototyping/trying out new ideas. The more you get to know Rails the less useful it becomes. Its probably Rails' most overrated feature.
    To me the best comparison is maybe to phpMyadmin. That's what scaffolding is for. A nicer interface to managing the database.
    Erh

  5. #5
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it's good to have a scaffold because 1) you can enter test data and 2) you have something to start with.

  6. #6
    SitePoint Addict DevilBear's Avatar
    Join Date
    Oct 2001
    Location
    Hades
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its only real purpose is in learning Rails and quickly prototyping/trying out new ideas. The more you get to know Rails the less useful it becomes. Its probably Rails' most overrated feature.
    Hmm... I don't know Rails very well at all, and it's not seeming very useful ;-)

    It doesn't seem to help much in prototyping anything that involves more than one table. I TOLD Rails how these tables relate in their models, so why can't it generate the connected data automatically?

    If table1 has table2_id as a field, I would expect rails to be smart enough to spit table2.name out in the table1 scaffolding, instead of just skipping over it.

    content_columns is a misnomer... table2_id references very important content!

  7. #7
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said, scaffolding is very limited. Its just not designed to create fully-featured views for your relationships out of the box. Rails wont hold your hand, you still have to do some work yourself.

  8. #8
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because, if you wanted to create such a CMS, you could use a prepackaged application. It is not hard to get the relations to work with a simple selectbox.

  9. #9
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also check out the Scaffolding Extensions plugin which adds some support for table relationships. As with the default scaffolding though I imagine you will end up wanting to replace much of it, though it may be a good starting point for you.

    There's a link on the rails wiki.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •