# Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch

**URL:** <https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263>\
**Category:** Rails\
**Created:** [September 10, 2009, 10:21am UTC](https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263 "2009-09-10T10:21:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [September 10, 2009, 10:21am UTC](https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263/1 "2009-09-10T10:21:14Z")

</div>

Hi,

I have been trying to do this for a few days now and cannot figure it  
out. I would be very grateful is anyone can help me

I am trying to upload an attachment to AWS, S3 using paperclip,  
however every time I keep getting this error:

ActiveRecord::AssociationTypeMismatch in  
ProjectController#create\_notice

Graphic(#37649720) expected, got Tempfile(#27280470)

RAILS\_ROOT: C:/devlopment\_tools/projects/codex1/active/bugtrigger  
Application Trace | Framework Trace | Full Trace

c:/devlopment\_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/  
lib/  
active\_record/associations/association\_proxy.rb:263:in  
`raise_on_type_mismatch' c:/devlopment_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/ lib/ active_record/associations/has_one_association.rb:52:in`replace’  
c:/devlopment\_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/  
lib/  
active\_record/associations.rb:1246:in `graphic=' c:/devlopment_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/ lib/ active_record/base.rb:2740:in`send’  
c:/devlopment\_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/  
lib/  
active\_record/base.rb:2740:in `attributes=' c:/devlopment_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/ lib/ active_record/base.rb:2736:in`each’  
c:/devlopment\_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/  
lib/  
active\_record/base.rb:2736:in `attributes=' c:/devlopment_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/ lib/ active_record/base.rb:2434:in`initialize’  
c:/devlopment\_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/  
lib/  
active\_record/base.rb:721:in `new' c:/devlopment_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/ lib/ active_record/base.rb:721:in`create’  
C:/devlopment\_tools/projects/codex1/active/bugtrigger/app/controllers/  
project\_controller.rb:128:in `create\_notice’

The code is:

–Notice Model  
class Notice \< ActiveRecord::Base  
has\_many :graphics  
end

–Project Controller  
def create\_notice  
@notice = Notice.create(params[:notice])  
end

–Form  
\<%= form.file\_field(:graphic) %\>

–Graphic  
class Graphic \< ActiveRecord::Base  
belongs\_to :notice  
attr\_accessor :notice\_id  
has\_attached\_file :graphic,  
:storage =\> :s3,  
:s3\_credentials =\> RAILS\_ROOT + “/config/  
s3.yml”,  
:path =\> “:attachment/:id/:style.:extension”,  
:bucket =\> “attachements”  
end

Thanks!

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [September 10, 2009, 11:30am UTC](https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263/2 "2009-09-10T11:30:19Z")

</div>

Try this out

On Thu, Sep 10, 2009 at 1:49 PM, codex1 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ProjectController#create\_notice  
> c:/devlopment\_tools/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/  
> active\_record/base.rb:2740:in `attributes=’  
> lib/  
> –Notice Model  
> \<%= form.file\_field(:graphic) %\>  
> :bucket =\> “attachements”  
> end

has\_attached\_file :graphic,  
:storage =\> :s3,  
:path =\> “:attachment/:id.:extension”,  
:s3\_credentials =\> open( “#{RAILS\_ROOT}/config/s3.yml”, ‘r’ ),  
:s3\_permissions =\> ‘public-read’,  
:bucket =\> ApplicationConfig[‘s3\_buckets’][‘graphics’][  
‘graphic’ ]

> Thanks!
> 
> >

–  
Ruby on Rails Developer

> **[Judul Situs](https://funonrails.wordpress.com/)**
>
> “Cinta tidak mengenal batas. Cinta mampu melewati rintangan, melompati pagar, menembus dinding untuk mencapai tujuannya dengan penuh harapan.” — Maya Angelou

> **[Josh Software | Custom Software Development Services & Solutions](https://joshsoftware.com/)**
>
> JoshSoftware offers custom software development Services & Solution that provides enterprise, software development services for web & mobile.

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [September 10, 2009, 12:40pm UTC](https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263/3 "2009-09-10T12:40:35Z")

</div>

Thanks, but still getting the same error.

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [September 10, 2009, 12:35pm UTC](https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263/4 "2009-09-10T12:35:18Z")

</div>

Hi,  
Thanks for that, but I am still getting the same error.

Not sure where to go with this

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [September 15, 2009, 2:42pm UTC](https://www.ruby-forum.com/t/paperclip-attachment-to-aws-activerecord-associationtypemismatch/175263/5 "2009-09-15T14:42:14Z")

</div>

What is current trace…?

–Sandip
