Displaying 20 results from an estimated 20000 matches similar to: "Validates uniqueness scope"
2013 Apr 03
1
validates uniqueness scope allow_blank/allow_nil -> validation error
I have this in a model:
class GenreBadge < ActiveRecord::Base
belongs_to :game, counter_cache: :genre_badges_count, touch: true
belongs_to :genre
validates :game_id, uniqueness: {scope: :genre_id}, allow_blank:
true
end
When I get one existing genre badge
genre_badge = game.genre_badges.first
genre_badge.game_id = nil
genre_badge.save!
It creates an validation exception:
2006 May 18
0
[newbie]problem when using validates*
Hi,
I have performed the cookbook tutorial. Before tailoring the views and
controllers, when I put in the model recipe.rb:
validates_uniqueness_of :title
validates_length_of :title, :within => 1...20
And I tried to introduce some new recipe without the above conditions I
got the message:
---------------------------------------------------
New recipe
1 error prohibited this category from
2010 Jan 28
1
validates preference of at least one param
I have a simple RESTful search scaffold that finds data in a separate
model and controller.
[code]
<h1>New search</h1>
<% form_for(@search) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :category_id %><br />
<%= f.collection_select :category_id, Category.all, :id, :name,
:include_blank => true %>
</p>
<p>
Age
2013 May 07
3
validates :uniqueness apparently doesn't
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]
Rails 3.2.13
I have a validates ... :uniqueness constraint on one of the attributes
of an ActiveRecord class.
In my test suite, I set the attribute from the same attribute in a
record in the fixture. I then send invalid? to the object under test.
invalid? returns _false_, and the .errors object for the record shows no
errors.
A
2009 Sep 25
12
uniqueness validation perplexity
I want to write a validate routine to check to enforce that a position
must be unique in a category. (In another category, it doesn''t have
to and shouldn''t need to be unique.) I write this code which works
happily for new items:
def position_in_category_not_unique
@items = Item.find( :all, :conditions => [ "category_id = ? AND
position = ?", category_id,
2006 May 18
6
Newbie:problem when using validates*
Hi,
I have performed the cookbook tutorial. Before tailoring the views and
controllers, when I put in the model recipe.rb:
validates_uniqueness_of :title
validates_length_of :title, :within => 1...20
And I tried to introduce some new recipe without the above conditions I
got the message:
---------------------------------------------------
New recipe
1 error prohibited this category from
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
2005 Dec 20
0
validates_uniqueness_of on has_and_belongs_to_many
I am trying to create a model that allows only unique assets to be
added to a category. However, they could be added again to a different
category. Finally, an asset can be shared across many categories. So
my question is how do you check the uniqueness across a join table?
This does not compile....
has_and_belongs_to_many :categories, :foreign_key => ''asset_id''
2006 Jul 07
0
has_many relation handling
Hello,
please have a look at this:
My tables:
create_table :languages do |t|
t.column :name, :string, :limit => 3
t.column :title, :string, :limit => 30
end
create_table :categories do |t|
t.column :category_id, :integer (3.)
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
end
create_table :categorytranslations, :id
2011 Feb 24
1
Rails 3 save parent model and association if nested attributes validation fails for uniqueness
Hi,
Song
has_and_belongs_to_many :people
accepts_nested_attributes_for :people
Person
validates :uniqueness => true
If person record not present, nested attributes working great! in rails way.
i.e., inserting into songs, people and people_songs table correctly.
I am interested in:-
*If there is person exist, it should skip insertion into people table but
data should be inserted in songs and
2011 Sep 27
0
accepts_nested_attributes_for is not working for uniqueness
class User < ActiveRecord::Base
accepts_nested_attributes_for :emails, :allow_destroy => true,
:reject_if => proc { |attributes| attributes[''address''].blank? }
end
class Email < ActiveRecord::Base
belongs_to :user
validates_presence_of :address
validates_email_format_of :address
validates_uniqueness_of :address,
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having
trouble getting my validation not to trigger. Here''s the code:
# spec:
Image.stub!(:find).and_return(@image)
@image.should_receive(:save!).once.with(:any_args)
put :update, :id => @image.id, :category_id =>
@category.id, :image => {:name => ''test'', :image_number =>
2006 Jun 29
0
How to validate uniqueness only if value exists
I''m looking for the best way to use validation to confirm that an
optional field (hostname) is unique only if a value is entered in the
form.
I was originally following the path shown in Agile Web Development with
Rails first edition, page 66, to define the "validate" method, but
didn''t have a clue how to include a uniqueness test there. Right now, I
have the
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
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 Jul 12
1
odd habtm behavior? or is it me?
Hello List,
I''m a bit spent on this problem, and my code might be whack. I seem to be
encountering a problem where the primary key on a join table is not being
resolved correctly. I will elaborate after some code bits. I am creating
the join table using migrations, and relevant model code is this:
class Post < ActiveRecord::Base
has_and_belongs_to_many :records
2005 Aug 19
2
data validation
I''m trying validate date before they''re stored into the DB, but it seems,
validation doesn''t work..
my model looks like this:
class Company < ActiveRecord::Base
has_many :contacts,
:foreign_key =>''company_id''
has_and_belongs_to_many :categories, :join_table => ''company_to_category'',
:foreign_key =>
2006 Apr 28
2
validates* gives me problems
Hi,
In Debian/testing (mysql-5.0.20, ruby1.8, rails 1.1.0)
Im trying to follow up the fourdaysonrails tutorial, and when putting:
validates_uniqueness_of :category, :message => "Already exists"
in /myapplication/app/model/category.rb
I get:
NoMethodError in Categories#create
undefined method `category'' for #<Article:0x407f6418>
RAILS_ROOT:
2006 Apr 01
3
acts_as_list with scope : position update problem?
Hello,
I''ve tried to set up a class with acts_as_list with a scope argument
that restricts a list to records with the same foreign key.
For example :
database :
CREATE TABLE `families` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '''',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
INSERT INTO
2010 Aug 15
1
Can save object via console, but not in app's controller
My app has a ''page'' model and a ''category'' model.
''Page'' belongs_to :category.
''Category'' has_many :pages.
From the console I can create and save a page object with no problems:
>> p = Page.new
#<Page id: nil, title: nil, body: nil, created_at: nil, updated_at: nil,
published: nil, read_counter: nil, category_id: