To ask an id, object should placed in variable which should contain exactly this object, so code should look like this:
post '/upload' do
params.delete 'submit'
u = UsrUpld.new(
:name => params[:name],
:created_at => Time.now
)
u.save
params[:photos].each do |photo|
unless File.exists?('public/media/' + u.id)
Dir.mkdir('public/media/' + u.id)
end
File.open('public/uploads/' + u.id + '/' + photo[:filename], 'w') do |file|
file.write(photo[:tempfile].read)
end
end
redirect '/index'
end
Also dir should exist before opening the file, thats why Dir.mkdir line added.