SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick tip for "Protective Measures" > "Displaying The Submitter" in "Simply Rails 2"

    To get around the issues described in the box called "Data Integrity in Development", run the following at the console:

    Code:
    s = Story.find(:all)
    s.each do |x|
    x.user_id = 1
    x.save
    end
    If you don't have a User with a user_id of 1, edit as required.

    Will be obvious to old-timers, but I was pleased to find my own user for Ruby's Blocks. Maybe it'll help someone else.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code posted in this thread works as long as there is a user defined, and therefore doesn't rely on there being a user with id = 1

    Code:
    # find the first user
    user = User.find(:first)
    # then get all the stories
    stories = Story.find(:all)
    # then assign the first user to all the stories
    for story in stories
      story.user = user
      story.save
    end


Tags for this Thread

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
  •