I ran into this weird issue with attachment_fu and had no idea what was wrong with my code. I’m using ActiveScaffold and attachment_fu to manage my entities and images. The exception was not that useful and I only found the solution thanks to Diego, our Rails guru @ Aycron.
Here is the exception:NoMethodError (undefined method `content_type’ for “10.jpg”:String):
/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:294:in `uploaded_data=’
/vendor/plugins/active_scaffold/lib/attribute_params.rb:106:in `send’
/vendor/plugins/active_scaffold/lib/attribute_params.rb:106:in `update_record_from_params’
/vendor/plugins/active_scaffold/lib/data_structures/action_columns.rb:68:in `each’
/vendor/plugins/active_scaffold/lib/data_structures/action_columns.rb:55:in `each’
/vendor/plugins/active_scaffold/lib/attribute_params.rb:49:in `update_record_from_params’
/vendor/plugins/active_scaffold/lib/attribute_params.rb:71:in `update_record_from_params’
/vendor/plugins/active_scaffold/lib/data_structures/action_columns.rb:68:in `each’
/vendor/plugins/active_scaffold/lib/data_structures/action_columns.rb:55:in `each’
/vendor/plugins/active_scaffold/lib/attribute_params.rb:49:in `update_record_from_params’
/vendor/plugins/active_scaffold/lib/actions/create.rb:73:in `do_create’
/Users/etagwerker/.gem/ruby/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction’
/Users/etagwerker/.gem/ruby/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in `transaction’
/vendor/plugins/active_scaffold/lib/actions/create.rb:72:in `do_create’
/vendor/plugins/active_scaffold/lib/actions/create.rb:28:in `create’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue’
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action’
/Users/etagwerker/.gem/ruby/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache’
/Users/etagwerker/.gem/ruby/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi’
/Users/etagwerker/.gem/ruby/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:76:in `process’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in `synchronize’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in `process’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load’
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load’
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load’
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require’
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in’
/Users/etagwerker/.gem/ruby/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require’
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
/script/server:3
-e:2:in `load’
-e:2
My code was organized so that a Page entity had one Image entity. The data structure was correct. The problem was in my controllers. images_controller was fine. I could check that by uploading images using that particular controller. The problem was with pages_controller. pages_controller uses images_controller to create/edit pages and their associated images.
pages_controller was missing a few lines of ActiveScaffold configuration. Particularly the lines associated with multipart forms. See ActiveScaffold:: create API.
The solution is to add the following lines to the pages_controller ActiveScaffold configuration:
config.create.multipart = true
config.update.multipart = true
That did the trick. I’m writing this down here so that I don’t forget the solution. Oh and maybe someone else will find this useful, if they ever run into such a useless exception message.
attachment_fu + ActiveScaffold 1.1.1: 'content_type' problem and solution
I ran into this weird issue with attachment_fu and had no idea what was wrong with my code. I’m using ActiveScaffold and attachment_fu to manage my entities and images. The exception was not that useful and I only found the solution thanks to Diego, our Rails guru @ Aycron.
My code was organized so that a Page entity had one Image entity. The data structure was correct. The problem was in my controllers. images_controller was fine. I could check that by uploading images using that particular controller. The problem was with pages_controller. pages_controller uses images_controller to create/edit pages and their associated images.
pages_controller was missing a few lines of ActiveScaffold configuration. Particularly the lines associated with multipart forms. See ActiveScaffold:: create API.
The solution is to add the following lines to the pages_controller ActiveScaffold configuration:
That did the trick. I’m writing this down here so that I don’t forget the solution. Oh and maybe someone else will find this useful, if they ever run into such a useless exception message.