icke
2009-Nov-26 16:12 UTC
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.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Abhishek shukla
2009-Nov-27 06:56 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
If you get a solution please share/. On Thu, Nov 26, 2009 at 9:42 PM, icke <owain.mcguire-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
sami
2009-Nov-27 14:44 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
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:" %> On Nov 26, 11:12 pm, icke <owain.mcgu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.Syed Samiuzzaman software Engineer Code71 Inc (www.code71.com) product: www.scrumpad.com blog: samiuzzaman.blogspot.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
icke
2009-Nov-27 15:44 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
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>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2009-Nov-27 15:52 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
2009/11/26 icke <owain.mcguire-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> 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:" %>Does this help at all? https://rails.lighthouseapp.com/projects/8994/tickets/3172-problem-with-error_messages_for-in-rails-234 Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
icke
2009-Nov-27 18:44 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
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.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Abhishek shukla
2009-Nov-28 08:41 UTC
Re: Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
Hello Friends, I have successfully Implemented "custom-err-msg<http://rubyforge.org/projects/custom-err-msg/>" http://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 On Sat, Nov 28, 2009 at 12:14 AM, icke <owain.mcguire-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
icke
2009-Nov-30 15:30 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Abhishek shukla
2009-Nov-30 16:01 UTC
Re: Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
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. On Mon, Nov 30, 2009 at 9:00 PM, icke <owain.mcguire-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
icke
2009-Dec-01 10:51 UTC
Re: ActionView::TemplateError (can''t convert ActiveRecord::Error into String)
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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.