Hi All,
Please help me ,I need to look into this issue asap, I need to change
the redmine functionality of uploading files to disk to upload them to
database. I tried suggestion on
http://dizzy.co.uk/ruby_on_rails/contents/store-file-uploads-in-database
but no luck , My form is multipart but still getting the error.
Please bare with me I am new to ruby and rails.
Here is the like for my redmine question
http://www.redmine.org/boards/2/topics/7737
I need to change Redmine functionality to upload files directly to
database and not to local filesystem. *
1. What I think is that I should add a field to "Attachments" table.*
I did this via this following migration
class AddFileToAttachments < ActiveRecord::Migration
def self.up
add_column :"attachments", :"file", :binary, :limit
=>10.megabytes
end end
def self.down
drop_column :"attachments", :"file"
end
2. Now I should change the model code to copy the file content into the
blob.
I updated attachment.rb , just added the line self.file @temp_file.read
as I need to read the content of file and put it into database.
def file=(incoming_file)
unless incoming_file.nil?
@temp_file = incoming_file
if @temp_file.size > 0
self.filename = sanitize_filename(@temp_file.original_filename)
self.disk_filename = Attachment.disk_filename(filename)
self.content_type = @temp_file.content_type.to_s.chomp
self.filesize = @temp_file.size
self.file = @temp_file.read
end
end
end
But After doing so I am getting the following error: Anybody please give
some direction
ndefined method `original_filename'' for #<String:0x8c09038>
RAILS_ROOT: C:/InstantRails/rails_apps/redmine
Application Trace | Framework Trace | Full Trace
app/models/attachment.rb:56:in `file=''
app/models/attachment.rb:60:in `file=''
app/controllers/application.rb:183:in `attach_files''
app/controllers/application.rb:180:in `each_value''
app/controllers/application.rb:180:in `attach_files''
app/controllers/projects_controller.rb:195:in `add_file''
vendor/rails/activerecord/lib/active_record/base.rb:2372:in `send''
vendor/rails/activerecord/lib/active_record/base.rb:2372:in
`attributes=''
vendor/rails/activerecord/lib/active_record/base.rb:2371:in `each''
vendor/rails/activerecord/lib/active_record/base.rb:2371:in
`attributes=''
vendor/rails/activerecord/lib/active_record/base.rb:2141:in
`initialize''
vendor/rails/activerecord/lib/active_record/base.rb:642:in `new''
vendor/rails/activerecord/lib/active_record/base.rb:642:in `create''
vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `send''
vendor/rails/actionpack/lib/action_controller/base.rb:1166:in
`perform_action_without_filters''
vendor/rails/actionpack/lib/action_controller/filters.rb:579:in
`call_filters''
vendor/rails/actionpack/lib/action_controller/filters.rb:572:in
`perform_action_without_benchmark''
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue''
C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure''
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue''
vendor/rails/actionpack/lib/action_controller/rescue.rb:201:in
`perform_action_without_caching''
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in
`perform_action''
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache''
vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache''
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in
`perform_action''
vendor/rails/actionpack/lib/action_controller/base.rb:529:in `send''
vendor/rails/actionpack/lib/action_controller/base.rb:529:in
`process_without_filters''
vendor/rails/actionpack/lib/action_controller/filters.rb:568:in
`process_without_session_management_support''
vendor/rails/actionpack/lib/action_controller/session_management.rb:130:in
`process''
vendor/rails/actionpack/lib/action_controller/base.rb:389:in `process''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:in
`handle_request''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in
`dispatch''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in
`synchronize''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in
`dispatch''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:in
`dispatch_cgi''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:35:in
`dispatch''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:76:in
`process''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in
`synchronize''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in
`process''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in
`process_client''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`each''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`process_client''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`initialize''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`new''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`initialize''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`new''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`each''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
`load''
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
`load''
vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in
`new_constants_in''
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
`load''
vendor/rails/railties/lib/commands/servers/mongrel.rb:64
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require''
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require''
vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in
`require''
vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in
`new_constants_in''
vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in
`require''
vendor/rails/railties/lib/commands/server.rb:39
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require''
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require''
script/server:3
app/models/attachment.rb:56:in `file=''
app/models/attachment.rb:60:in `file=''
vendor/rails/activerecord/lib/active_record/base.rb:2372:in `send''
vendor/rails/activerecord/lib/active_record/base.rb:2372:in
`attributes=''
vendor/rails/activerecord/lib/active_record/base.rb:2371:in `each''
vendor/rails/activerecord/lib/active_record/base.rb:2371:in
`attributes=''
vendor/rails/activerecord/lib/active_record/base.rb:2141:in
`initialize''
vendor/rails/activerecord/lib/active_record/base.rb:642:in `new''
vendor/rails/activerecord/lib/active_record/base.rb:642:in `create''
app/controllers/application.rb:183:in `attach_files''
app/controllers/application.rb:180:in `each_value''
app/controllers/application.rb:180:in `attach_files''
app/controllers/projects_controller.rb:195:in `add_file''
vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `send''
vendor/rails/actionpack/lib/action_controller/base.rb:1166:in
`perform_action_without_filters''
vendor/rails/actionpack/lib/action_controller/filters.rb:579:in
`call_filters''
vendor/rails/actionpack/lib/action_controller/filters.rb:572:in
`perform_action_without_benchmark''
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue''
C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure''
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue''
vendor/rails/actionpack/lib/action_controller/rescue.rb:201:in
`perform_action_without_caching''
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in
`perform_action''
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache''
vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache''
vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in
`perform_action''
vendor/rails/actionpack/lib/action_controller/base.rb:529:in `send''
vendor/rails/actionpack/lib/action_controller/base.rb:529:in
`process_without_filters''
vendor/rails/actionpack/lib/action_controller/filters.rb:568:in
`process_without_session_management_support''
vendor/rails/actionpack/lib/action_controller/session_management.rb:130:in
`process''
vendor/rails/actionpack/lib/action_controller/base.rb:389:in `process''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:in
`handle_request''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in
`dispatch''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in
`synchronize''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in
`dispatch''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:in
`dispatch_cgi''
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:35:in
`dispatch''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:76:in
`process''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in
`synchronize''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in
`process''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in
`process_client''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`each''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in
`process_client''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`initialize''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`new''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`initialize''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`new''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`each''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in
`run''
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
`load''
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
`load''
vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in
`new_constants_in''
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
`load''
vendor/rails/railties/lib/commands/servers/mongrel.rb:64
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require''
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require''
vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in
`require''
vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in
`new_constants_in''
vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in
`require''
vendor/rails/railties/lib/commands/server.rb:39
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require''
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require''
script/server:3
Request
Parameters:
{"commit"=>"Add",
"id"=>"saur",
"attachments"=>{"1"=>{"description"=>"ss",
"file"=>#<File:C:/DOCUME~1/sauragar/LOCALS~1/Temp/CGI3868-0>}}}
Show session dump
---
projectslist_files_sort:
:order: asc
:key: filename
:user_id: 1
adminprojects_sort:
:order: asc
:key: name
issuesindex_sort:
:order: desc
:key: id
flash: !map:ActionController::Flash::FlashHash {}
:query:
:project_id: 1
:filters:
tracker_id:
:values:
- "1"
:operator: "="
status_id:
:values:
- ""
:operator: o
Response
Headers:
{"cookie"=>[],
"Cache-Control"=>"no-cache"}
Thanks & Regards
Saurabh
--
Posted via http://www.ruby-forum.com/.