Displaying 20 results from an estimated 3000 matches similar to: "Custom error messages"
2006 Apr 07
2
errors.add_to_base
What are the limitations on using:
errors.add_to_base
to display errors in views?
I have tried for days to add errors from my object.rb and they never get
displayed.
class Keyword < ActiveRecord::Base
validates_presence_of(:name, :message => "Name is required.")
validates_uniqueness_of(:name, :message => "This name is already in
use. Please try
2009 Apr 02
3
error_messages_for does not display the error
Hi all
I''ve approached Rails since a couple of months to develop a quick
application for my company. Fantastic framework. As every noob, I do
have some gaps to cover. The one which is giving me a little
frustration, generated by my lack of knowledge is as follows.
I need to make sure the region object is not deleted if there are
countries associated with it. I solved this by putting a
2006 Aug 09
6
How to change the error message easy way
validates_presence_of :fname
results in the error message
"Fname can''t be blank".
What I want is "First Name can''t be blank".
I could do this
def validate
errors.add_to_base("First Name can''t be blank") if fname.blank?
end
I find this clunky and I have to put everyrhing in the validate method. Is
there an easy to get what I want.
I
2009 Nov 26
9
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'',
2006 Jan 19
1
Model Validation & Floating Attributes
Hello all !
I have a model being validated that spits it''s error messages on the
resulting page using:
error_messages_for(:mymodel) .... Basic stuff. It''s working perfectly.
Now, I have something else I want to check on the same page (that isn''t an
attribute to the Model)... and am trying to add it using:
@mymodel.errors.add_to_base("another error here")
2006 Jun 13
7
help with ''error_messages_for''
Greetings,
I''m in the throws of deploying an app on site5, and I''m getting strange
errors. I think I might need to understand how error_messages_for
works.
I get a pretty standard looking error:
"
You have a nil object when you didn''t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occured while evaluating nil.errors
Extracted
2006 Feb 28
1
adding to errors in controller?
def update
@product = Product.find(params[:id])
@product.attributes = params[:product]
if params[:main_image]
image = Image.new params[:main_image]
if image.save
@product.main_image.destroy if @product.main_image
@product.main_image = image
else
@product.errors.add_to_base(image.errors.full_messages.join(", "))
end
end
2009 Feb 05
6
get # of errors in error_messages_for
hi everyone here i go again, i have problem we error message validation
here is the sample of my code:
error_messages_for :user, :header_message => ''X errors, please find red
mark'', :message => ''Following errors were found:''
the problem is that how where going to get the value "X errors" or the
number of errors if they have when the is
2006 Jul 20
7
How do you use :message with validation?
If I do validates_uniqueness_of :name, :message => "It''s not
uniqueeee!!!"
then how do I have it display that message when the check fails?
-Ben Lisbakken
--
Posted via http://www.ruby-forum.com/.
2007 Jun 10
2
custom errors for validates_presence, etc..
I am trying to figure out how to customize the error messages when I use
validates_presence_of. I am validating a user name and I use <%=
error_messages_for ''user'' %> in my view to display the messages. I know
you can customize in the model with :message =>''custom message'', but I
am trying to get rid of the first part of the error message which is,
1
2009 Jun 11
8
before_create return value breaking object.save: rails bug?
I know that usually when people say ''i think i found a bug in
rails/ruby'' they''ve done something dumb. I''m wondering if this is the
case here, but this does seem like a genuine rails bug to me.
In my user model i have a few different before_create callbacks. In one
of them, if it happens to return false (just because the last statement
in it evaluated to
2006 Jan 27
17
Multiple Model Validation
Hey All !
I have a form which contains two models. I would like both models to be
validated, but have their validations aggregated on the page.
If I do:
<%= error_messages_for(:model1) %>
<%= error_messages_for(:model2) %>
It puts two big validation blocks on the page. I would like all the errors
from both models, but only in one validation box.
Is this possible ? All my attempts
2008 Jun 02
5
validate - message in the flash[:error]
Hi,
I want to show the validate - message in the flash[:error] - field but I
can''t find any options.
An example:
class UserPermission < ActiveRecord::Base
validates_presence_of :name,
:message => "Please insert a name"
... |
end V
flash[:error] = "Error - "
Has anybody a solution for this
2006 Dec 12
2
Error message translation
I have a problem with translation of english phrase when an input error
occurs. When I put: error_messages_for("registratie") above my view. I
get the error: "xx errors prohibited this registratie from being saved".
The problem now is, the site is for dutch customers and I would like to
translate this to a dutch phrase. I know I can translate the individual
fields with the
2010 Aug 18
7
error_messages_for doesn't work
I''m having a problem, ''cause I wrote the following line in my model
"Hi":
[code]
validates_numericality_of :phone, :only_integer => true, :allow_blank =>
false, :message => "must be a number"
[/code]
And in my "new" view, I put:
[code]
<%= error_messages_for :oi,
:header_message => "Erro ao cadastrar
2006 Jun 29
1
before_destroy & verification
Hey, probably an easy question but,
I''m trying to get a method to run "before_destory" for a model, and I
want the method to throw an error, and not delete the object from the
database, if a certain condition is held
Obviously, I can just raise an error and rescue it... but for some
reason I can''t get <% error_messages_for ''model" %> to catch
2006 May 26
4
Using ''validates_inclusion_of'' to validate foreign key
I seem to be missing something trying to use ''validates_inclusion_of'' to
validate a foreign key and was hoping some one could piont out my
mistake?
The problem seems to be that Order.find_all.collect is not returning an
array that contains the order_id, if I replace it with a hardcoded array
everything works as expected.
The model:
class OrderItem < ActiveRecord::Base
2007 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model?
I''m assuming i need to say
@mock_thing = mock_model(Thing)
@mock_thing_errors = mock("errors")
@mock_thing_errors.should_receive(:full_messages).and_return("An error")
@mock_thing.should_receive(:errors).and_return(@mock_thing_errors)
Just wanted to check the best practice on this kind of thing and how
2006 Feb 21
2
validations and directing errors
I am starting to play with validations as I want to catch errors before
SQL rejects inserts to the table which are ugly when nulls are sent to
''Not Null'' columns, etc.
If I do something in my model like...
validates_format_of :first_name,
:with => /^\w+$/,
:message => "you moron, enter a name"
I still end up
2005 Dec 19
7
Error handling!
Hello all,
I''m in the beginning states of learning ruby on rails development and
have got to a part where I''m a little stuck! Basically writing a simple
blog application, just to try something completely different! ;-)
I have a page which displays the current blog entry, it''s comments and
at the bottom of the page, a form to add a comment. So far, so good.