Pulling ID from a just saved object?

Hi,

Can anyone tell me how I can pull a full url from an object I just
saved?

I need to send the saved object’s id to my thanks_url so I can build
another object in the thanks_url view.

if @video.save
flash[:notice] = “”
redirect_to thanks_url

else
  ....

end

Thanks!

-Mario

##FULL CODE

def new_video
@band = Band.find_by_id(params[:band_id])
return unless @band

# fix swfupload ampersand issue
params[:video_data] ||= params['amp;video_data']

# load data from form through swfupload
if params[:video_data]
  params[:video] ||= Marshal.load(params[:video_data]) #rescue {}
  # move swf's data to the proper key
  params[:video][:filename] = params[:Filedata]
end


@video = Video.new(params[:video])
@video.slug = URI.escape(@video.name)
@video.user_id = current_user.id
@video.band = @band

return unless request.post?

unless params[:Filename]
  if @video.valid?
    @temp = params[:video]
    @upload = true
    @old_params = {
      :video_data => Marshal.dump(params[:video])
    }
  end
  return
end


# Note: swfupload only cares about status code of the response, it

does
# not follow redirections, you will have use it’s callbacks.
if @video.save
flash[:notice] = “”
redirect_to thanks_url

else
raise @video.errors.inspect
  render and return false
end

end

I realized I could just do this,

@video.save
@video.id

My problem was that becuase of a data error, the video wasn’t saving in
the first place.

Thanks,

-Mario

On 10/25/07, Mario F. [email protected] wrote:

I realized I could just do this,

@video.save
@video.id

My problem was that becuase of a data error, the video wasn’t saving in
the first place.

You might want to consider using save! instead of save.

On a validation error save will return false, while save! will raise
an exception.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/