Displaying 20 results from an estimated 40000 matches similar to: "How to validate uniqueness only if value exists"
2005 Oct 21
4
Validate uniqueness on two columns
I would like to validate the uniqueness of two columns together. I have last
and first names as separate columns. What is the Rails Way to do this?
Thanks,
Jared Nuzzolillo
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
2006 Feb 17
2
validate uniqueness of two fields
I have Proposals and Members and Members can vote for a proposal only once.
So, I have "Vote belongs_to :member, :proposal", but to make sure a member only votes
once, I want to make sure that there isn''t a vote in the db with that member_id and
proposal_id. I can just put the appropriate find in a vote.valid? but I wanted to make
sure I wasn''t missing a nice rails
2006 Apr 14
1
Validating Existing Models
I''ve got a user object which has quite a few attributes mapped to the
database. As of right now I''ve got some validations in the model like:
validates_presence_of :password, :message => "You must specify a valid
password."
validates_confirmation_of :password, :message => "Password doesn''t match
the confirmation."
validates_presence_of
2006 May 31
3
validate unless, LoginGenerator difficulty
I apologize if this is a very simple question; I''ve searched the forums,
wiki, Google, and Agile Web Development with Rails to no avail.
Is there a way to put conditional validation in the model? For
instance, if I want to limit items a user can add unless the user is an
admin? My current code is:
validates_uniqueness_of :user_id, :scope => ''event_id'',
2010 Mar 21
0
Validates uniqueness scope
In a Rails 2.x validation to check if the name of some model is unique
within a some category, I would use:
`validates_uniqueness_of :name, :scope => :category_id`
In Rails 3, this is replaced with:
`validates :name, :uniqueness => true`
However, I can''t seem to find a method of defining the uniqueness''
scope. Am I missing something?
Thanks,
Angelo
--
You received
2006 Jan 20
3
Is there a way to validate a model w/o saving it?
I have some code in my controller which looks like this:
if request.post? and @account.save and @user.save
...
end
and in my Account and User models I have many :validates, like so
account.rb
validates_presence_of :subdomain, :on => :create
validates_uniqueness_of :subdomain, :on => :create, :message => "is
already being used"
validates_exclusion_of
2006 Jul 15
0
Validate using boolean values
The Problem: how to do the validation. I have not written it
correctly!!!
Given two tables: sizes and prices;
with a relation: has_many ,belongs_to
a Price.unit_price for a given Size.meassure must be
marked ''true'' as the standard unit_price for that meassure.
There will be many other unit_prices for a given meassure, those must be
marked ''false''
table
2007 Jul 30
3
validates_uniqueness_of doesn't work if value tested is numeric and column is string
Hello all,
I am working through the depot example in the rails book. If I add a
validates_uniqueness_of to a string column in the model, and then try
to create a record with a number in this string column I get an SQL
error. Looks like the SQL generated to test for uniqueness does not
quote the value if it''s numeric even though it''s comparing against a
varchar column. It does
2007 Sep 02
2
problem validating uniqueness
I have validates_uniqueness_of :name in my model which works fine when
creating a record but doesn''t work when I edit the record. In other
words it won''t let me create a record with the same name but I can go
in after and update the field without a problem. Why would this
happen? -Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you
2006 May 26
2
validates_uniqueness_of but only when exists
I want to validate the uniqueness of a field if the field has a value.
Is there anyway to do it?
--
Posted via http://www.ruby-forum.com/.
2012 Oct 24
1
Uniqueness and sql serialize
Hi fellow programmers,
I was looking for how to keep integrity in some financial transactions and
I saw this "This could even happen if you use transactions with the
‘serializable’ isolation level." in the uniqueness page
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_uniqueness_of.
How this is possible with the serializablo
2008 May 09
4
Validating Uniqueness From Two Database Tables?
Well, I''m working on adding a new type of user (organization) to my
application, using a different database table than the standard User
table (in the end, I think it works out being easier to deal with than
creating another column in the original User table for account type).
However, I''m running into a user registration problem. I can register
both types of users fine,
2006 Jul 28
0
Dreamhost, fastcgi, validates_uniqueness_of.... is not always unique?
Hey everyone,
I have an application running on dreamhost with fast cgi (FCGI). I have a
model, "Member", that has the following validation:
validates_uniqueness_of :email, :if =>
Proc.new{|member| !member.email.blank?}
The :if clause is really not needed because an email address is required and
in fact the model also has:
validates_presence_of :email
2005 Dec 29
3
Verification problems
Hello,
Hope this isn''t a newbie question - but I don''t seem to be able to find
relevent information elsewhere.
I am having trouble getting the following to work:
Schema
======
ActiveRecord::Schema.define(:version => 1) do
create_table "authors", :force => true do |t|
t.column "name", :string
end
create_table "books", :force =>
2006 May 10
4
validates_uniqueness_of and create atomicity
Hi folks,
I have a question regarding validates_uniqueness_of, and similar
before-filter-like events attempting to guarantee some DB state prior
to modification.
>From my reading of ActiveRecord, validate_uniqueness_of appears to
cause a SELECT on the underlying table attempting to ensure that a
record with ID(s) specified in the validates_uniqueness_of statement
is not already present, prior
2005 Mar 10
2
NoMethodError in Event_type#create
I am new Ruby on Rails, so excuse me if my question seems pretty obvious.
I am trying to validate uniqueness of a filed:
class EventType < ActiveRecord::Base
belongs_to :sport
validates_uniqueness_of :event_type
end
When I run it, I get this error message:
Showing /event_type/new.rhtml where line #27 raised undefined method
`each'' for nil:NilClass
<select
2012 Jun 06
1
Default value for case sensitive on uniqueness validator
Hello,
The uniqueness validator was always case sensitive but that seems wrong because we want uniqueness validations to be insensitive in most of the time.
Do not make more sense be insensitive by default and set sensitive only where it should be?
We are migrating a lot of big applications from mysql to postgresql here and we are setting case sensitive to false on **all** uniqueness
2009 Mar 19
0
Single-table inheritance and validation problem
Hi!
I''ve got a subscription form in which someone can decide to give a
gift to someone else. So you have to enter subscriber and recipient
data in one form.
For my user model I use single-table inheritance. It works fine but
I''ve got a bug in the validation which I''m not able to solve.
For both users, subscriber and recipient, you have to enter an email
address. It is
2006 May 10
1
Validates_uniqueness_of multiple field combo?
Hello,
I am new to Ruby on rails and this is therefore probably trivial. Lets
say I have 3 tables - users[id,name, age, ...],
interests[id,name,description, ...], and finally a table
user_interests[id,user_id,interest_id] to link a user to a set of
interests. Now there is no problem to put validates_uniqueness_of :name
in the user-model to ensure that I only have one Lenny, but how do I
2007 Apr 20
0
Rails validations, how to improve them
Here is a discussion of a problem and potential solution for Rails
validations.
Rails has a fundamental problem with validations in that it essentially
requires you to either
1. Accept the default error messages (which can often lead to ugly and
unfriendly messages for the user)
2. Override validation messages at the model level like so
validates_uniqueness_of :field, :message =>