Uploading files using Ruby on Rails

Issues related to building and deploying Ruby on Rails.
no avatar
tutorialspoint
Site Admin
 
Posts: 144
Joined: Fri Apr 27, 2007 6:52 pm

Uploading files using Ruby on Rails

by tutorialspoint » Wed Jan 16, 2008 4:30 pm

Hi!

Here is simple tutorial to understand how to upload a file to a web server using Ruby on Rails framework.

http://www.tutorialspoint.com/ruby-on-r ... oading.htm


Thanks
Moderator, TP
Keep visiting and share this site with your friends.

no avatar
etopit46
 
Posts: 1
Joined: Tue Apr 22, 2008 9:19 pm

Upload Problem

by etopit46 » Tue Apr 22, 2008 9:22 pm

Hey,

This tutorial seems great, and is exactly what I'm trying to figure out. Unfortunately, every time I try to upload something using the form I have created I get this error:

NoMethodError in UploadController#uploadFile

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

RAILS_ROOT: C:/rails/upload
Application Trace | Framework Trace | Full Trace

app/controllers/upload_controller.rb:6:in `uploadFile'

c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
c:/rails/lib/ruby/1.8/benchmark.rb:293:in `measure'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
c:/rails/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
c:/rails/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:112:in `handle_dispatch'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:78:in `service'
c:/rails/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
c:/rails/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
c:/rails/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
c:/rails/lib/ruby/1.8/webrick/server.rb:162:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
c:/rails/lib/ruby/1.8/webrick/server.rb:95:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:92:in `each'
c:/rails/lib/ruby/1.8/webrick/server.rb:92:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:23:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:82:in `start'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:62:in `dispatch'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/webrick.rb:66
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
c:/rails/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
c:/rails/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
c:/rails/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
script/server:3

app/controllers/upload_controller.rb:6:in `uploadFile'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
c:/rails/lib/ruby/1.8/benchmark.rb:293:in `measure'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
c:/rails/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
c:/rails/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
c:/rails/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:112:in `handle_dispatch'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:78:in `service'
c:/rails/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
c:/rails/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
c:/rails/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
c:/rails/lib/ruby/1.8/webrick/server.rb:162:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
c:/rails/lib/ruby/1.8/webrick/server.rb:95:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:92:in `each'
c:/rails/lib/ruby/1.8/webrick/server.rb:92:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:23:in `start'
c:/rails/lib/ruby/1.8/webrick/server.rb:82:in `start'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:62:in `dispatch'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/webrick.rb:66
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
c:/rails/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
c:/rails/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
c:/rails/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
c:/rails/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
c:/rails/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
script/server:3

Request

Parameters:

{"commit"=>"Upload",
"authenticity_token"=>"fc2a3321360815eb77b71c2ccb9d9f42528ba867",
"upload"=>{"datafile"=>#<File:C:/DOCUME~1/estern/LOCALS~1/Temp/CGI.3896.1>}}

Show session dump

---
:csrf_id: c2ce42d773f52553be9b20e1e251c923
flash: !map:ActionController::Flash::FlashHash {}


Response

Headers:

{"cookie"=>[],
"Cache-Control"=>"no-cache"}
-----------------------------------------------

Any help is appreciated!

-Ethan

no avatar
compuwhiz
 
Posts: 1
Joined: Fri Sep 18, 2009 12:45 am

by compuwhiz » Fri Sep 18, 2009 12:54 am

I am also having this problem. I'm guessing it has to do with the CGI object upload? Is there something I need to have installed?

Return to Ruby on Rails

cron