title: can't cast ActionDispatch::Http::UploadedFile to string in ActiveAdmin
body: <p>I've spent something like a day and a half on this matter and can't seem to find where the issue is. I would very much appreciate your input. </p>
  
  <p>So, I have to upload a file and store it in public/documents/ as well store the path to it and it's name in a db table made for that purpose. 
  I've first handled this as a feature on the front-end and it worked fine (uploaded files and created records in the table). </p>
  
  <p>Next I tried to implement this in ActiveAdmin and that's where all my pain started. </p>
  
  <p>Here's what I have so far: </p>
  
  <p><strong>DocumentsController create method:</strong></p>
  
  <pre><code>def create
          @static_pages = StaticPage.all
          @document = Document.new(doc_params)
          @uploaded_document = @document.upload(doc_params)
          if @uploaded_document
              @document.location = @uploaded_document[:loc]
              @document.doc_type = @uploaded_document[:doc_type]
              if @document.save
                  flash[:notice] = "Document uploaded successfully"
                  redirect_to admin_documents_path
              end
          else
              @document.errors.add(attr, "There was a problem uploading the file")
          end
      end
  
      private 
  
      def doc_params
          params.require(:document).permit :name, :location, :doc_type, :static_page_id
      end
  </code></pre>
  
  <p><strong>Document Model with the upload method used above:</strong> </p>
  
  <pre><code>class Document &lt; ActiveRecord::Base
  
      belongs_to :static_page
  
      validates :name, presence: true, uniqueness: true
      validates :location, presence: true, uniqueness: true
      validates :doc_type, presence: true
      validates :static_page, presence: true
  
      def upload(doc_params)
          # Take upload from params[:file] and store it somehow...
      # Optionally also accept params[:hint] and consume if needed
      dirname = 'documents'
      name = doc_params[:location].original_filename #doc_params[:location].original_filename
      type = name.split('.').last
  
        Dir.mkdir("public/#{dirname}") unless Dir.exists?("public/#{dirname}")
        filepath = "public/#{dirname}"
  
      path = File.join(filepath, name)
      File.open(path, "wb") { |f| f.write(doc_params[:location].read) } 
      path = dirname + '/' + name
      document = { loc: path, doc_type: type }
      end
  end
  </code></pre>
  
  <p><strong>And the Active Admin resource definition:</strong> </p>
  
  <pre><code>ActiveAdmin.register Document do
      #actions :all, :except =&gt; [:destroy, :new, :edit]
  
      index do 
          column :name, sortable: :name do |document|
              link_to document.name, admin_document_path(document)
          end
          column :doc_type, sortable: :doc_type do |document|
              link_to document.doc_type, admin_document_path(document)
          end
          column :static_page, sortable: :static_page do |document|
              link_to document.static_page.title, admin_document_path(document)
          end
          column :created_at, sortable: :created_at do |document|
              link_to document.created_at, admin_document_path(document)
          end
      end
  
      form :html =&gt; { :enctype =&gt; "multipart/form-data" } do |f|
      f.inputs  :multipart =&gt; true do 
        f.input :name
        f.input :location, :as =&gt; :file
        f.input :static_page_id, :label =&gt; 'Parent Static Page', :as =&gt; :select, :collection =&gt; StaticPage.all.map{|sp| ["#{sp.title}", sp.id]}
      end
      f.actions
    end
  
    show do |form|
      attributes_table do
        row :id
        row :name
        row :location
        row :type
        row :static_page
      end
    end
  
          permit_params :name, :static_page_id, :location
  end
  </code></pre>
  
  <p>When I try to upload a file from the ActiveAdmin page it shows the following error message: </p>
  
  <pre><code>can't cast ActionDispatch::Http::UploadedFile to string
  
  Rails.root: /home/sly/ruby/fletcher
  Application Trace | Framework Trace | Full Trace
  
  activerecord (4.1.6) lib/active_record/connection_adapters/abstract/quoting.rb:76:in `type_cast'
  activerecord (4.1.6) lib/active_record/connection_adapters/postgresql/quoting.rb:136:in `type_cast'
  activerecord (4.1.6) lib/active_record/validations/uniqueness.rb:64:in `build_relation'
  activerecord (4.1.6) lib/active_record/validations/uniqueness.rb:19:in `validate_each'
  activemodel (4.1.6) lib/active_model/validator.rb:167:in `block in validate'
  activemodel (4.1.6) lib/active_model/validator.rb:164:in `each'
  activemodel (4.1.6) lib/active_model/validator.rb:164:in `validate'
  activesupport (4.1.6) lib/active_support/callbacks.rb:447:in `public_send'
  activesupport (4.1.6) lib/active_support/callbacks.rb:447:in `block in make_lambda'
  activesupport (4.1.6) lib/active_support/callbacks.rb:184:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:184:in `block in simple'
  activesupport (4.1.6) lib/active_support/callbacks.rb:185:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:185:in `block in simple'
  activesupport (4.1.6) lib/active_support/callbacks.rb:185:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:185:in `block in simple'
  activesupport (4.1.6) lib/active_support/callbacks.rb:185:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:185:in `block in simple'
  activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `run_callbacks'
  activemodel (4.1.6) lib/active_model/validations.rb:376:in `run_validations!'
  activemodel (4.1.6) lib/active_model/validations/callbacks.rb:111:in `block in run_validations!'
  activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
  activemodel (4.1.6) lib/active_model/validations/callbacks.rb:111:in `run_validations!'
  activemodel (4.1.6) lib/active_model/validations.rb:317:in `valid?'
  activerecord (4.1.6) lib/active_record/validations.rb:70:in `valid?'
  activerecord (4.1.6) lib/active_record/validations.rb:77:in `perform_validations'
  activerecord (4.1.6) lib/active_record/validations.rb:51:in `save'
  activerecord (4.1.6) lib/active_record/attribute_methods/dirty.rb:21:in `save'
  activerecord (4.1.6) lib/active_record/transactions.rb:268:in `block (2 levels) in save'
  activerecord (4.1.6) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
  activerecord (4.1.6) lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
  activerecord (4.1.6) lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
  activerecord (4.1.6) lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
  activerecord (4.1.6) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (4.1.6) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
  activerecord (4.1.6) lib/active_record/transactions.rb:268:in `block in save'
  activerecord (4.1.6) lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
  activerecord (4.1.6) lib/active_record/transactions.rb:267:in `save'
  /home/sly/.rvmruby (2.1.2) bundler/gems/activeadmin-6344d2924517/lib/active_admin/resource_controller/data_access.rb:158:in `block in save_resource'
  activesupport (4.1.6) lib/active_support/core_ext/object/try.rb:45:in `call'
  activesupport (4.1.6) lib/active_support/core_ext/object/try.rb:45:in `public_send'
  activesupport (4.1.6) lib/active_support/core_ext/object/try.rb:45:in `try'
  /home/sly/.rvmruby (2.1.2) bundler/gems/activeadmin-6344d2924517/lib/active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
  /home/sly/.rvmruby (2.1.2) bundler/gems/activeadmin-6344d2924517/lib/active_admin/resource_controller/data_access.rb:157:in `save_resource'
  /home/sly/.rvmruby (2.1.2) bundler/gems/activeadmin-6344d2924517/lib/active_admin/resource_controller/data_access.rb:147:in `block in create_resource'
  activesupport (4.1.6) lib/active_support/core_ext/object/try.rb:45:in `call'
  activesupport (4.1.6) lib/active_support/core_ext/object/try.rb:45:in `public_send'
  activesupport (4.1.6) lib/active_support/core_ext/object/try.rb:45:in `try'
  /home/sly/.rvmruby (2.1.2) bundler/gems/activeadmin-6344d2924517/lib/active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
  /home/sly/.rvmruby (2.1.2) bundler/gems/activeadmin-6344d2924517/lib/active_admin/resource_controller/data_access.rb:146:in `create_resource'
  inherited_resources (1.4.1) lib/inherited_resources/actions.rb:33:in `create'
  actionpack (4.1.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.6) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.1.6) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.6) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.6) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.6) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.6) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.1.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.6) lib/action_controller/metal.rb:232:in `block in action'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:82:in `call'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:50:in `call'
  actionpack (4.1.6) lib/action_dispatch/journey/router.rb:73:in `block in call'
  actionpack (4.1.6) lib/action_dispatch/journey/router.rb:59:in `each'
  actionpack (4.1.6) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:678:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `catch'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/flash.rb:254:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.1.6) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
  activerecord (4.1.6) lib/active_record/migration.rb:380:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.6) lib/rails/engine.rb:514:in `call'
  railties (4.1.6) lib/rails/application.rb:144:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /home/sly/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  /home/sly/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  /home/sly/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
  
  Request
  
  Parameters:
  
  {"utf8"=&gt;"✓",
   "authenticity_token"=&gt;"rUZ0xBtYmYu+HdpZQalOXqh5wZdgiKHm8fuTuUKu6o4=",
   "document"=&gt;{"name"=&gt;"Sample new Doc",
   "location"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0xc01ac64 @tempfile=#&lt;Tempfile:/tmp/user/1000/RackMultipart20141006-13048-9uig4j&gt;,
   @original_filename="SvetoslavBlyahov_portfolio.pdf",
   @content_type="application/force-download",
   @headers="Content-Disposition: form-data; name=\"document[location]\"; filename=\"SvetoslavBlyahov_portfolio.pdf\"\r\nContent-Type: application/force-download\r\n"&gt;,
   "static_page_id"=&gt;"1"},
   "commit"=&gt;"Create Document",
   "locale"=&gt;"en"}
  </code></pre>
  
  <p>I've tried so many different approaches in attempt to investigate the issue I don't know what else to do. From the stand point of this feature working our of AA and not in, I am pretty sure it's coming from Active Admin. But I don't know how to fix it. Suppose it's this part: </p>
  
  <blockquote>
    <p>f.input :location, :as => :file</p>
  </blockquote>
  
  <p>as :location's field type in the DB is :string so I could save the path to the saved file on the storage. Yet I had no other way to make the field allow file upload. </p>
  
  <p>Any advice would be highly appreciated. </p>
  
  <p>Thank you.</p>