image upload problem

8 views
Skip to first unread message

john paul

unread,
Aug 10, 2011, 7:15:52 AM8/10/11
to rubyonra...@googlegroups.com
Hi team,

    I doing one rails application , i have doubt i can create user form  and upload images ,  i did create user(using session ) and create tmp folder and save the database  my issue is 

my error is:

undefindedmeth'[]'

error came that place:

name= Upload['imagepath'].original_filename

please slove the problem



my code :
**********************************************
@login=Upload.new(params[:userform])
      session[:user] = Upload.new(params[:userform])
@sn= session[:user].name
@pn= session[:user].email
@ss=FileUtils.mkdir_p("tmp/session/#{@sn}")
name= Upload['imagepath'].original_filename
directory="tmp/session/#{@sn}"
path=File.join(directory,name)
@str=directory+"/"+name
 
File.open(path,"wb"){|f|f.write(upload['imagepath'].read)}
@upload=Upload.new
#@upload=ImagePath.save(params[:upload])
@upload['name']=@sn
@upload['email']=@pn
@upload['userpath']=@ss
#@upload['imagepath']=@str
#@upload=DataFile.save(params[:upload])
@upload.save
puts "****************"
puts @sn
puts @ss
#puts @str 
end
def uploadfile

Tim Shaffer

unread,
Aug 10, 2011, 10:35:08 AM8/10/11
to rubyonra...@googlegroups.com
You're trying to call ['imagepath'] on your Upload class. I'm not entirely sure what you're trying to do with that line of code?

Maybe you meant to do something like this and call it on the instance of the Upload class?

  session[:user].imagepath

Have you thought about using something like "will_paginate" to handle your file uploads? It would probably make your life a lot easier.

Tim Shaffer

unread,
Aug 10, 2011, 10:35:37 AM8/10/11
to rubyonra...@googlegroups.com
I meant to say "paperclip" instead of "will_paginate". That's what I get for reading more than one thread at once :)
Reply all
Reply to author
Forward
0 new messages