SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie needs help! show by project_id and not id?

    Im very much a newbie to ruby, and am stuck with what is probably a very simple fix...

    I am creating a system that creates html pages, which a client can download.

    So, I have one project, that has many details, meta tags, images etc. Each one of these has its own model, and db table, and they are all setup with has_many (Project) and belongs_to (details, meta tags, images etc) relationships.

    This all worked fine, create, show, edit etc until the database id fields on the tables went out of sync during working on the validations.

    So I added in the project_id column on the tables as a backup plan so they are not all running off the id column that auto increments...

    Now, when I click 'show' on my project, I get the error: Couldn't find Image with ID=43, and thats because there is no image with the id on the table as it went out of sync.

    So how do I make it so that when I click 'show', it gets the project_id of the image instead of the id?

    Hope that makes sense? It may not be the best way of doing it, and im still learning, so any suggestions are welcomed.

  2. #2
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by erin09 View Post
    Hope that makes sense?
    Not really. Maybe it's just the lateness of the hour but I'm having trouble envisioning it. (maybe it's just the concept of a project belonging to a meta tag that's bugging me.)

    Seriously, if your ids are "out of sync" then I'd either pull out a database editor and get them back into sync, or wipe them all out and start over. The worst thing in the world is to suddenly create a new column and try to switch over to using that. Since we're just talking development, I'd think it was simpler to just go "Oops" and start over.

  3. #3
    SitePoint Enthusiast TomK32's Avatar
    Join Date
    Mar 2008
    Location
    Berchtesgaden, Germany
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please post code (or put it at http://gist.github.com/ ) from your models and controlers and your db schema as well.
    just a geek trying to change the world
    I'm a ruby on rails developer in Vienna, Austria. My github.

  4. #4
    SitePoint Member
    Join Date
    May 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply.

    I figured it out... all I needed was: @image = Image.find_by_project_id(project_id)

    I thought it would be an easy fix.


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
  •