ActionView::TemplateError (can't convert ActiveRecord::Error into String)

I cannot work out why this error is appearing.

ActionView::TemplateError (can't convert ActiveRecord::Error into String) on line #3 of app/views/button/_show_enquiry.html.erb: 1: <h1>Send us a message</h1> 2: <% remote_form_for :enquiry, :url => {:action => 'send_mail'} do | f> %> 3: <%= error_messages_for 'enquiry', :header_message => "Please try again!", :message => "We need you to change some items in order to send us a message:" %> 4: <table> 5: <tr><td>Name:</td> <td><%= f.text_field :name, :size => 30 %></td></tr> 6: <tr><td>Contact tel:</td> <td><%= f.text_field :tel, :size => 30 %></td></tr>

    app/views/button/_show_enquiry.html.erb:3     app/views/button/_show_enquiry.html.erb:2     app/views/button/enquiry.rjs:1:in `_run_rjs_app47views47button47enquiry46rjs'     app/views/button/enquiry.rjs:1:in `_run_rjs_app47views47button47enquiry46rjs'     app/controllers/button_controller.rb:24:in `send_mail'     app/controllers/button_controller.rb:17:in `send_mail'

Here is the partial that is doing the rendering:

<h1>Send us a message</h1> <% remote_form_for :enquiry, :url => {:action => 'send_mail'} do |f| %>   <%= error_messages_for :enquiry, :header_message => "Please try again!", :message => "We need you to change some items in order to send us a message:" %>   <table>       <tr><td>Name:</td> <td><%= f.text_field :name, :size => 30 %></td></tr>       <tr><td>Contact tel:</td> <td><%= f.text_field :tel, :size => 30 %></td></tr>       <tr><td>Email Address:</td> <td><%= f.text_field :email, :size => 30 %></td></tr>       <tr><td>Subject:</td> <td><%= f.text_field :subject, :size => 30 %></td></tr>       <tr><td>Message:</td> <td><%= f.text_area :message, :rows => 8, :cols => 30 %></td></tr>   </table>   <%= submit_tag("Send") %> <% end %>

And the partial is invoked by:

page.replace_html 'enquirybox', :partial => 'show_enquiry', :locals => {:enquiry => @enquiry}

in turn invoked from an ajax request from:

    respond_to do |format|       format.js do         if @enquiry.save           Emailer.deliver_contact_email(@enquiry)           flash[:firstname] = @enquiry.firstname           render :action => 'thank_you'         else           render :action => 'enquiry'         end       end       format.html     end

Anyone have any ideas?

O.

The only difference from the 'norm' is that I am using the custom-err- msg plugin.

O.

If you get a solution please share/.

did you try with <%= error_messages_for 'enquiry',:object=>@enquery, :header_message => "Please try again!", :message => "We need you to change some items in order to send us a message:" %>

No luck on that.

ActionView::TemplateError (can't convert ActiveRecord::Error into String) on line #3 of app/views/button/_show_enquiry.html.erb: 1: <h1>Send us a message</h1> 2: <% remote_form_for :enquiry, :url => {:action => 'send_mail'} do | f> %> 3: <%= error_messages_for 'enquiry', :object => @enquiry, :header_message => "Please try again!", :message => "We need you to change some items in order to send us a message:" %> 4: <table> 5: <tr><td>Name:</td> <td><%= f.text_field :name, :size => 30 %></td></tr> 6: <tr><td>Contact tel:</td> <td><%= f.text_field :tel, :size => 30 %></td></tr>

Does this help at all? https://rails.lighthouseapp.com/projects/8994/tickets/3172-problem-with-error_messages_for-in-rails-234

Colin

Colin (and Sami)

Indeed, your link is relevant as I use the http://rubyforge.org/projects/custom-err-msg/ plugin to over-ride the error messages. I notice that it hasn't changed since early January this year so is it a 2.3.4 update to Active Record that is causing some sort of compatability problem? The plugin code is below. Any ideas? The model which is doing the validation is below too.

module ActiveRecord   class Errors

    # Redefine the ActiveRecord::Errors::full_messages method:     # Returns all the full error messages in an array. 'Base' messages are handled as usual.     # Non-base messages are prefixed with the attribute name as usual UNLESS     # (1) they begin with '^' in which case the attribute name is omitted.     # E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'     # (2) the message is a proc, in which case the proc is invoked on the model object.     # E.g. validates_presence_of :assessment_answer_option_id,     # :message => Proc.new { |aa| "#{aa.label} (#{aa.group_label}) is required" }     # which gives an error message like:     # Rate (Accuracy) is required     def full_messages       full_messages =

      @errors.each_key do |attr|         @errors[attr].each do |msg|           next if msg.nil?

          if attr == "base"             full_messages << msg           elsif msg =~ /^\^/             full_messages << msg[1..-1]           elsif msg.is_a? Proc             full_messages << msg.call(@base)           else             full_messages << @base.class.human_attribute_name(attr) + " " + msg           end         end       end

      return full_messages     end   end end

class Enquiry < ActiveRecord::Base

  validates_presence_of :name, :email, :subject, :message   validate :validate_email

  def name     firstname && lastname ? [firstname, lastname].join(' ') : ''   end

  def name=(n)     split = n.split(' ', 2)     self.firstname = split.first     self.lastname = split.last   end

  protected

  def validate_email     address = EmailVeracity::Address.new(email)     errors.add(:email, "^We suspect that the email address #{email} is incorrect.") unless address.valid?   end

end

Beer o'clock in the UK.

O.

Hello Friends, I have successfully Implemented “custom-err-msghttp://github.com/gumayunov/custom-err-msg Even I was getting error after installing the plugin. But What I did I simply copied “custom_error_message.rb” file from “vendor/plugins/custom-err-msg/lib/” to app lib folder. And its started working fine.

Let me know If this worked for u…

Thanks Abhis

Abhis,

Thank you for this suggestion but it did not work. I still suspect that is something to do with changes in Active Record 2.3.4

O.

Ok tell me did you installed the plugin from “http://github.com/gumayunov/custom-err-msg/tree” And then Did you copied “custom_error_message.rb” file from “vendor/plugins/custom-err-msg/lib/” to app lib folder.

I guess it should work.

And even I am running my app on rails version 2.3.4 with ruby 1.8.7

Though I did lot of stuff to resolve this issue. Ok let me experiment the same on a new application, will let you know soon.

Thanks Abhis.

Abhis,

Well figured. I had in fact installed the plugin from http://rubyforge.org/projects/custom-error-message/ which I think I picked up from one of the Railscasts. This project is now invalid so I am guessing that this has now been killed and that http://github.com/gumayunov/custom-err-msg/tree must be the "current version".

I am not sure how you are meant to keep track of things like that (Using GIT?) . My app started off under an earlier version of Rails and the plugin worked ok. It still does .... until last week!

Abhis awarded a Gold Star and a House Point.

O.