Displaying 20 results from an estimated 9000 matches similar to: "using database for validation"
2010 Apr 29
1
Setting a message on a model -without- errors.add_to_base
I''m trying my best to follow the skinny controller/fat model concept,
and I''ve got a series of callbacks (that I''m about to move into
observers) running on a few models. Based on what these callbacks do
to the data (it''s implementing business rules), I''d like to add some
type of message on the state of the model *without* invalidating it.
For example:
2006 Jul 18
2
validate method doesn''t recognize another instance method
All,
I am attempting 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")
2006 Aug 23
5
validation, concurrency, and transactions
Hi,
Something has been bothering me about model validation: how do I know that
the database has not changed in between when I validate my model''s data, and
when it actually gets saved to the database? As a simple example, say I have
a User model like:
class User
validates_uniqueness_of :username
end
When this gets saved to the database, the validation code checks that there is
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 Feb 16
1
Help with validation
I am trying to write some simple code post a form, update the database
and do some validation. I have 2 problems:
1) The validation fails but I can''t get hold of the error message
2) I can''t get the form to redisplay the previously entered data for the
user to correct.
I have 2 controllers:
user and holiday.
A user can request a new holiday by filling in a form. I have a
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.
Anyone know how to get rid of this?
Many thanks,
Mike
2006 Aug 26
3
order of saving/validating
Hi guys,
I''m trying to do some validation on an image upload. Basically I have
a model, Property, which has_many :property_images. I need to check
that one image has been uploaded at least and so it was suggested I
checked the number of images uploaded -
@property.property_images.count > 0. Makes sense.
I''ve added a validation on my Property model, like -
def
2006 Jan 12
0
Multi Row validation... or running queries within Validate function?
Is there anyway to perform a query from within a validate function?
I need to verify that the sum of several rows does not exceed a certain
value eg:
class Entry < ActiveRecord::Base
belongs_to :day
belongs_to :project
def validate
totalhours = hours
samedayentries = self.find_by_day_id(day_id)
samedayentries.each do
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
2010 Apr 09
0
Child to Parent Validation Errors
Hi:
Passing child virtual attribute validation error to parent...
in case of nested attributes.
So, I have a Parent Model say ''Parent''.
Nested Attributes it accepts for Child say ''Child''
Now suppose there is a validate method in ''Child''
and it has something like self.errors.add_to_base("some message").
How do you make sure that
2005 Dec 29
7
belongs_to causing NoMethodError exceptions ... ?
I''ve got a really strange problem using belongs_to. I apologize in
advance for the length... this is going to take a while to explain.
Basic idea: Creating a User requires that the user enter an email
address and activation key that matches an existing PendingUser.
After creating the user successfully, that pending user should be
marked as "used".
The problem:
When I
2006 Aug 14
2
after_create is not being called
Hi all
I have the following model:
class PhotoGallery < ActiveRecord::Base
attr_accessible :title, :description, :file_path, :title_photo_id
has_many :photos, :dependent => :destroy
belongs_to :title_photo,
:class_name => ''Photo'',
:foreign_key => ''title_photo_id''
validates_presence_of :title, :description, :file_path
2006 Jul 17
2
Very strange after_save problem. Please help.
I have a very strange problem here. I do not get this. So any help is
greatly appreciated.
Basically I have a model that calls a method in the background
process in the "after_save" method. Let''s call the model products. So
what happens is this:
1. I create a new product.
2. Everything works and the product is saved with id 13.
3. A method is called in my background
2009 Mar 29
2
after_create and after_save
Hi,
AFAIK after_create is called after_save if the entry does not exist in
the DB.
Is there a way to tell if a specific model is new or not in
after_save?
I have to do something like:
def after_save
add_to_history ''save''
end
def after_create
add_to_history ''create''
end
However after_save is called when creating too.
--
cheers,
M.
2009 Mar 11
1
How to dummy a DB adapter?
I am writing a library module to handle certain StatementInvalid type AR
exceptions. I wish to catch the case where the db adapter in use is not
supported by the module. I would like to test this situation and have
only a vague idea as to how to proceed.
My exception handling method selects the parsing method based on the
adapter_name value.
def hll_ar_exception(exception)
raise
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?
--
2008 Aug 01
0
Help with Access Control
Hi,
I am following the excellent tutorial http://www.railsforum.com/viewtopic.php?id=14216
(post 5) on how to implement an access control feature i.e. only a
friend is allowed to view a profile of a particular member. I am not
using the restful authentication plugin as the author is using to
implement the authentication feature (post 1) in the tutorial. All I
am interested in is the post 5
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,
2012 Jan 28
2
after_save in plugin
Dear list,
I am trying to override an after_save callback declared in main app
using plugin.
The main model class is:
class WorkHours < ActiveRecord::Base
@after_save_call_back_called=0
after_save :after_save_call_back
def after_save_call_back
logger.debug "after save called"
@after_save_call_back_called=1
end
end
And in my plugin (in the lib directory) :
module
2005 Aug 23
0
Fixtures: pluraly bitten
With my functional tests (on PgSQL) I get strange errors like this
1) Error:
test_create(AufgabeControllerTest):
ActiveRecord::StatementInvalid: ERROR: duplicate key violates unique
constraint "aufgaben_pkey"
Tracking this down, I found that sequences are only reset for some of
the tables I''m using. The reason? Inconsistent singularization.
I won''t go so far as