SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would I get the previous id from the database?

    I'm trying to get the id of the previous row prior to what would be
    input and then rename an uploaded image to that row number.

    So say the previous row was 19 and the image in that row was named
    19.jpg, I'm wanting to name the next uploaded image as 20.jpg since the
    row that would be added then would be 20.

    Right now I've just got:
    Code:
    @new_tutorial = Tutorial.new(params[:tutorial])
        File.open("#{RAILS_ROOT}/public/pictures/1.jpg", "wb") do |f|
          f.write(@params['image_url'].read)
        end
    Obviously the "1" in "1.jpg" needs to be dynamic.

  2. #2
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Once the new tutorial object has been saved you'll be able to get its ID by simply calling @new_tutorial.id

  3. #3
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File Column

    Not sure if this will help, but using the file_column plugin makes this kind of stuff really easy.

    http://www.kanthak.net/opensource/file_column/


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
  •