Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:50:12+00:00 2026-05-27T01:50:12+00:00

Rails 3.1.2 with mail gem 2.3.0 I’m trying to use ActionMailer with an ActiveModel

  • 0

Rails 3.1.2 with mail gem 2.3.0

I’m trying to use ActionMailer with an ActiveModel based form. I’ve defined my table less model like so:

class StprodApp 
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming
  attr_accessor :email,:name
  attr_reader :errors
  validates_presence_of :email, :message => "Please enter your email address"
  def initialize(attributes = {})
    attributes.each do |name, value|
    send("#{name}=", value)
   end
   @errors = ActiveModel::Errors.new(self)
 end
 def persisted?
   false
 end
end

So far so good, I can post a form based on stprod_app, and validations work

So now I want to send an email based off this model, so I do this in my create action:

@stprod_app = StprodApp.new(params[:stprod_app])
if @stprod_app.valid?
  EmployeeMailer.stprod_app(@stprod_app).deliver
end

I get this error

undefined method `index' for #<StprodApp:0x007f95325a1ad0>

and this stack trace

mail (2.3.0) lib/mail/encodings.rb:117:in `value_decode' 
mail (2.3.0) lib/mail/encodings.rb:101:in `decode_encode'
mail (2.3.0) lib/mail/fields/unstructured_field.rb:74:in `do_decode'
mail (2.3.0) lib/mail/fields/unstructured_field.rb:56:in `decoded'
mail (2.3.0) lib/mail/fields/unstructured_field.rb:107:in `wrapped_value'
mail (2.3.0) lib/mail/fields/unstructured_field.rb:70:in `do_encode'
mail (2.3.0) lib/mail/fields/unstructured_field.rb:52:in `encoded'
mail (2.3.0) lib/mail/field.rb:123:in `method_missing'
mail (2.3.0) lib/mail/header.rb:190:in `block in encoded'
mail (2.3.0) lib/mail/header.rb:189:in `each'
mail (2.3.0) lib/mail/header.rb:189:in `encoded'
mail (2.3.0) lib/mail/message.rb:1708:in `encoded'
actionmailer (3.1.2) lib/action_mailer/base.rb:451:in `set_payload_for_mail'
actionmailer (3.1.2) lib/action_mailer/base.rb:431:in `block in deliver_mail'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `block in
instrument'
activesupport (3.1.2) lib/active_support/notifications/instrumenter.rb:21:in
`instrument'
activesupport (3.1.2) lib/active_support/notifications.rb:53:in `instrument'
actionmailer (3.1.2) lib/action_mailer/base.rb:430:in `deliver_mail'
mail (2.3.0) lib/mail/message.rb:230:in `deliver'
app/controllers/stprod_app_controller.rb:20:in `create'

So I read the docs for the mail gem, and it says this:

—snip—

All objects that can render into an email, have an #encoded method. Encoded will return the object as a complete string ready to send in the mail system, that is, it will include the header field and value and CRLF at the end and wrapped as needed.

All objects that can render into an email, have a :decoded method. Decoded will return the object’s “value” only as a string. This means it will not include the header fields (like ‘To:’ or ‘Subject:’).

By default, calling #to_s on a container object will call its encoded method, while #to_s on a field object will call it’s decoded method. So calling #to_s on a Mail object will return the mail, all encoded ready to send, while calling #to_s on the From field or the body will return the decoded value of the object. The header object of Mail is considered a container. If you are in doubt, call #encoded, or #decoded explicitly, this is safer if you are not sure.

Structured fields that have parameter values that can be encoded (e.g. Content-Type) will provide decoded parameter values when you call the parameter names as methods against the object.

Structured fields that have parameter values that can be encoded (e.g. Content-Type) will provide encoded parameter values when you call the parameter names through the object.parameters[”] method call.

—snip—

It looks like the index error is Rail’s last desperate attempt to decode/encode? the email. The only ‘index’ I found in rails that makes sense is in ActiveSupport::Multibyte::Chars.

It sounds like I have to implement an encode/decode method in my ActiveModel, but I can’t figure out how!

Anybody know how to define an ActiveModel that works with ActionMailer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:50:13+00:00Added an answer on May 27, 2026 at 1:50 am

    Solved, left off a crucial detail, and therin lay the problem

    I was passing the Stprod_app instance variable to the mail call:

    def stprod_app(emp,app)
      @app = app
      @emp = emp
      mail(:to=> @app.antibot, 
        :from=>@emp.email, 
        :app=>@app) # <<< DOH!!!!
    

    Sorry!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use delayed_job gem https://github.com/collectiveidea/delayed_job in Rails 3.2 to send a mail
I'm trying to install: gem twitter-bootstrap-rails, :group => :assets But when I use bundle
Note: Using Rails 3.1 and current delayed_job gem. I have a User model that
I'm trying to use the rails plugin with hudson, but i'm getting the following
I'm trying to install the mysql2 gem with Rails 3.2.3 and it's failing: ★
I am trying to use the whenever gem to execute a couple of rake
I'm trying to read an email using ruby mail gem. But mail.body.decoded returns me
Rails 3.0.11 ruby 1.9.3dev (2011-09-23 revision 33323) [x86_64-linux] mail gem v. 2.2.19 postfix v.
something like this: gem install rails Fetching: activesupport-3.0.10.gem (100%) Fetching: builder-2.1.2.gem (100%) WARNING: builder-2.1.2
I was told to use v0.6.5 of the rails-i18n gem, so I first checked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.