Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch

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:inreplace’
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:insend’
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:ineach’
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:ininitialize’
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:increate’
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!

Try this out

On Thu, Sep 10, 2009 at 1:49 PM, codex1 [email protected] 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
http://funonrails.wordpress.com
www.joshsoftware.com

Thanks, but still getting the same error.

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

Not sure where to go with this

What is current trace…?

–Sandip

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs