I have a class that handles the form data and file stuff. In that class, I'm creating the first resource with @variables passed in from the params. All other args passed into this resource come from @variables that have values from the form. In this case, @url, the variable in question, is set to a value only a few lines before. Now when I put in the URL:
rec = Post.new(
# more args
:filename_ogg => @url
)
rec.save
This is the killer: Every other line of code in this file is able to access @url, through a global variable ($upload = Upload.new(file)), except for this resource creator. When it comes to saving the resource, it doesn't go through. BUT, when I replace @url with a static string like "RANDOM URL.", it works perfectly. Why?
This had been tested under both MRI 1.9.3 and JRuby 1.6.7.2 (1.9 mode) under Ubuntu 12.04:
# #{user} edited out, but the actual bucket name is in the actual file
class Upload
attr_accessor :file, :filename, :filename_ogg, :status, :title, :desc, :url
def initialize(file)
@file = file
@filename = @file[:filename].gsub(" ", "")
@filename_ogg = "#{@filename}.ogg"
#@url = "http://s3.amazonaws.com/#{user}/#{@filename_ogg}"
end
def downandup
# code
end
def convert(file, file_ogg)
# code
end
def upload(file_ogg)
# code
@url = "http://s3.amazonaws.com/#{user}/#{file_ogg}"
# title and desc are accessed through $upload.title/$upload.desc
rec = Post.new(
:title => @title,
:description => @desc,
:author_id => Random.rand(5),
:time_uploaded => Time.now,
:filename_ogg => @url,
:comments_table => Random.rand(10),
)
rec.save
end
end
The file runs through fine, but when it comes for DataMapper to put it in the database, it won't go in, but when replaced with the static string, the data gets stored.

New Topic/Question
Reply




MultiQuote






|