Displaying 20 results from an estimated 64 matches for "add_to_base".
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 nam...
2009 Dec 21
0
errors.add_to_base translation missing: en, activerecord
In my model I am using errors.add_to_base:
errors.add_to_base "Error 1"
This works fine.
If I do this twice:
errors.add_to_base "Error 1"
errors.add_to_base "Error 2"
I receive the message:
translation missing: en, activerecord, errors, models, modelname,
attributes, base,
as part of my error messages....
2010 Apr 29
1
Setting a message on a model -without- errors.add_to_base
...I''d like to add some
type of message on the state of the model *without* invalidating it.
For example:
class Order < ActiveRecord::Base
after_save :do_something_cool
private
def do_something_cool
# manipulates the order object in some way based on business rules
errors.add_to_base("Message about what we did to your order to
match said business rules")
end
end
I''d prefer to do this without calling errors.add_to_base, because it
isn''t an error. Furthermore, I don''t even think that works because
it''s being called -after- the mod...
2006 Aug 14
2
after_create is not being called
...s_name => ''Photo'',
:foreign_key => ''title_photo_id''
validates_presence_of :title, :description, :file_path
def after_validation
if !errors.invalid?("file_path")
images = get_images
if images.size == 0
errors.add_to_base("There are no files in the directory
#{get_images_path}")
else
errors.add_to_base(images.inspect)
end
end
rescue SystemCallError
errors.add_to_base("The directory #{get_images_path} does not
exist")
end
def after_create
if errors.empty?...
2006 Jul 18
2
validate method doesn''t recognize another instance method
...mpting to do some custom validation on my object.
Here is my validate method:
protected
def validate
puts "Do I have the target_list_ids method? " +
self.methods.include?(''target_list_ids'').to_s
if target_list_ids.nil? || target_list_ids.length == 0
errors.add_to_base("You must choose at least one target list for
this job")
end
puts "Do I have the Fax method? " +
self.methods.include?(''Fax'').to_s
if Fax.nil?
errors.add_to_base("You must choose at least one report
destination (either email or fax) f...
2006 May 02
1
Custom error messages
On a model I have the following simple validator:
def validate
unless name && name =~ /^\w+$/
errors.add_to_base("Name is missing")
end
end
I would like to display a custom message on my views, without using the
helper <%= error_messages_for "table" %>
Where the messages from errors.add_to_base are stored and how to access
them in the views?
--
Posted via http://www.ruby-for...
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 tried this also validates_presence_of :fname , :message => ''new message''
still retains the fname....
2009 Jun 25
4
standard ActiveRecord validation message
in testing my app I just use the validations
validates_presence_of :first_name, :last_name, :email
validates_presence_of :academy, :message => "You must select an
Academy"
validates_presence_of :role, :message => "You must select a role"
standard error_messages are fine for most of my fields , resulting
in :
5 errors prohibited this data from being saved
There
2006 Feb 18
6
Active Record errors value - Why doesn''t this work?
I''m creating an AR object in my controller and then attempting to add
error messages to it:
if (master_storeids.nil?)
@item.errors.add_to_base ''No store is selected''
end
This works without error but when it comes time for AR to add the
record, it apparently initializes the errors because the message that I
added does not cause the AR add to fail as you would expect.
Even when there is a validation error in AR the...
2005 Dec 30
2
before_create question
...User has_many Registration, Event has_many Registration, and
Registration belongs_to User and Registration. So far, so good.
There''s a registration deadline on a Event though, a few days before
the Event occurs.
So, I have this:
class Registration < AR
def before_create
errors.add_to_base("Registration deadline has passed") unless
event.can_still_register?
end
end
The weird thing is, if the registration deadline has passed, the error
gets added to the registration object, and calling save! throws no
exception, but the registration object doesn''t get saved.
So,...
2007 Sep 02
0
using database for validation
...first approach to this was to catch exceptions from save/
create and parse the errors, in my case from postgres, to turn them
into something friendlier. Something like:
def update
create
end
def create
begin
super
rescue ActiveRecord::StatementInvalid => e
errors.add_to_base(e.to_s)
end
end
but apparently rails ignores errors at this point. This just results
in rails thinking the record is saved when it has not been. So next I
tried something more elaborate. This is a bit contrived and I don''t
think I would actually use this but I''m just trying...
2006 Apr 22
4
How to supress field name in error message?
Hi
How do I supress the reporting of a field name in the full error
message? I want the error to be associated with the field so that the
.fieldWithErrors class is applied to the field but I don''t want it to
add the field name to the actual error message.
For example:
errors.add("occurs_on", "The date can''t be today!") unless occurs_on
!= Date.today
I
2010 Aug 01
3
The {{key}} interpolation syntax in I18n messages is deprecated...
...e to Rails 3 --- if you think this problem is
solved in Rails 3 then let me know):
The {{key}} interpolation syntax in I18n messages is deprecated. Please use
%{key} instead.
I have isolated the problem to the following line in my model --- when I do
not add this error everything is fine:
errors.add_to_base("Uploaded file must be present") if
!self.uploaded_file_content
Also tried this but same result:
errors.add(:uploaded_file_content, "Uploaded file must be present") if
!self.uploaded_file_content
The irony is on this app I have no use for i18n. Would be also just as glad
to...
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 Dec 15
2
Reading Model data before update
Hi all,
here is the challenge:
I have this validation method, that basically prevents an object which
billed = true to be updated:
def before_update
if read_attribute(:billed)
errors.add_to_base(''This service has already been billed for'')
end
!read_attribute(:billed)
end
The above code does not work in case I do something like:
object = Model.find(:first)
object.billed = true
object.save
because in my before_update filter I am reading the billed column,
that...
2006 Jul 12
1
validate method not getting called?
Here''s a snippet of my model:
validates_presence_of :from_name, :from_email, :reply_name,
:reply_email, :eSubject
protected
def validate
puts "Calling: #{target_list_ids}"
errors.add_to_base("You must choose at least one target list for
this job") if self.target_list_ids.nil?
end
It appears that the validates_presence_of are being called just fine,
but my validate method is not. I never see the puts message that I
inserted to prove that it was being called.
Anyone eve...
2006 Jan 19
1
Model Validation & Floating Attributes
...s 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")
However... this doesn''t seem to be working. On the view, the custom error
message isn''t being displayed... only the ones from default validation.
When doing an inspect on the model, here is what I see:
#<MyModel:0x4089b20c @errors=#<ActiveR...
2006 Feb 28
1
adding to errors in controller?
...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
if @product.errors.empty? and @product.save
flash[:notice] = "Product was successfully updated"
redirect_to :action => "show", :id => @product
else
render :action => ''...
2008 Mar 20
0
Having trouble with a remote-crop-then-resize using attachment fu =(
...ata].size > 0
avatar.uploaded_data = (params[:uploaded_avatar_data])
avatar.thumbnails.clear
avatar.save!
self.avatar = avatar
end
save!
end
rescue
if avatar.errors.on(:size)
errors.add_to_base("Uploaded image is too big (500-KB
max).")
end
if avatar.errors.on(:content_type)
errors.add_to_base("Uploaded image content-type is not
valid.")
end
false
end
end
--~--~---------~--~----~------------~-------~--~----~
You rece...
2006 Apr 01
4
Custom Validations
Does anyone how to create a validation that:
validates_presence_of :a OR :b
I.e. :a OR :b must be present.
I thought this would probably be possible with some kind of validation
callback, e.g.:
def check_a_or_b_is_set
return (a or b)
end
Any ideas?
Thanks,
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: