Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving Email (ActionMailer) with Rails to process image attachments
    primarykey
    data
    text
    <p>I am trying to parse an email sent to my app server. It should read the email to find the user by email then add the photo to the user's photo models Here is what I have so far. What am I doing wrong? </p> <pre><code>class Mailman &lt; ActionMailer::Base def receive(email) logger.info("Got an email about: #{email.subject}") if (@user = User.find_by_email(email.from)) if email.has_attachments? for attachment in email.attachments #...@user.photos.create(:data_file_name =&gt; attachment.original_filename, # :data_content_type =&gt; attachment.content_type, :data_file_size =&gt; attachment.size, # :data_updated_at =&gt; Time.now.to_datetime) # @user.photos &lt;&lt; attachment # I don't think this is the right way to do this... end end else logger.info("No user found with email: #{email.from}") end end end class User &lt; ActiveRecord::Base acts_as_authentic has_attached_file :avatar has_many :photos, :dependent =&gt; :destroy accepts_nested_attributes_for :photos # What does this do? end class Photo &lt; ActiveRecord::Base belongs_to :user has_attached_file :data end class AddAttachmentsDataToPhoto &lt; ActiveRecord::Migration def self.up add_column :photos, :data_file_name, :string add_column :photos, :data_content_type, :string add_column :photos, :data_file_size, :integer add_column :photos, :data_updated_at, :datetime end def self.down remove_column :photos, :data_file_name remove_column :photos, :data_content_type remove_column :photos, :data_file_size remove_column :photos, :data_updated_at end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload