Actionmailer + attachment_fu

image model

class Image < ActiveRecord::Base
has_attachment
end

mailman controller

class Mailman < ActionMailer::Base
def receive(email)
email.attachments.each do |attachment|
Image.create :uploaded_data => attachment
end
end
end

I got returned email with error messages

Command died with status 1: “/usr/local/bin/ruby
/home/email_test/script/runner ‘Mailman.receive(STDIN.read)’”. =
Command
output:
=
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/runner.rb:47:
/usr/local/lib/ruby/1.8/tempfile.rb:46:in initialize': cannot = generate tempfile =/home/email_test/script/…/config/…/tmp/attachment_fu/11862540901020801=
593_f62fd725ce18176-9.jpg’
(RuntimeError) from
=
/home/email_test/script/…/config/…/vendor/plugins/attachment_fu/lib/tec=
hnoweenie/attachment_fu.rb:170:in
new' from = /home/email_test/script/../config/../vendor/plugins/attachment_fu/lib/tec= hnoweenie/attachment_fu.rb:170:inwrite_to_temp_file’ from
=
/home/email_test/script/…/config/…/vendor/plugins/attachment_fu/lib/tec=
hnoweenie/attachment_fu.rb:304:in
write_to_temp_file' from = /home/email_test/script/../config/../vendor/plugins/attachment_fu/lib/tec= hnoweenie/attachment_fu.rb:294:intemp_data=3D’ from
=
/home/email_test/script/…/config/…/vendor/plugins/attachment_fu/lib/tec=
hnoweenie/attachment_fu.rb:259:in
uploaded_data=3D' from = /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/b= ase.rb:1672:insend’ from
=
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/b=
ase.rb:1672:in
attributes=3D' from = /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/b= ase.rb:1671:ineach’ … 11 levels… from
=
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/runner.rb:47
from =
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’ from /home/email_test/script/runner:3

On 8/25/07, Sean K. [email protected] wrote:

def receive(email)
  email.attachments.each do |attachment|
    Image.create :uploaded_data => attachment
  end
end

end

You’re not uploading data, so it’s not really appropriate to use that
method. You’ll have to set the fields manually then (filename,
content type, etc). A future update to the plugin will be able to
guess the content type for you based on the file.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com