Displaying 20 results from an estimated 5000 matches similar to: "rake test and validates_inclusion_of"
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
2005 Feb 09
1
[DEFECT] ''validates_inclusion_of'' not working as expected (couldn''t post to Trac as it gave me an error)
Hello,
I tried to post this as a bug on the trac site, but whenever I hit
submit, I got the error message:
---
Precondition Failed
The precondition on the request for the URL /newticket evaluated to false.
---
Anyway...
Let''s say I have the following model classes:
---
class Project < ActiveRecord::Base
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to
2006 Mar 21
5
Order records based on number of children
Let''s say I have simple schema with two tables. The models are defined
like the folllowing:
class Parent < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
Simple has_many relationship. Is there any way to order the results of
a Parent.find_all by the number of children the parent has? I can
sort with
sorted_parents =
2006 Mar 24
6
Should counter_cache fields be saved in the database?
As far as I can tell, the counter_cache option on a belongs_to model
doesn''t actually save anything in the database. For example, I have
the following models:
class Parent < ActiveRecord::Base
has_many :children,
:conditions => "deleted_at IS NULL"
end
class Child < ActiveRecord::Base
belongs_to :parent, :counter_cache => true
end
With the following
2006 Apr 08
4
Calling validates_inclusion_of out of default namespace
Hi,
I''m trying to run the "validates_inclusion_of" method in a before_save hook,
because the range is dependant on the related data. But I can''t figure out how
to call it. When calling it normally, it says it can''t find it.
I''ve tried several combinations like
"ActiveRecord::Validations.validates_inclusion_of", but I can''t seem to
2006 Feb 14
2
confusion with validates_inclusion_of
It appears that if your trying to use validates_inclusion_of for a
string value allow_nil wont work. For example, if I have an attribute
:year which is stored as a varchar then:
validates_inclusion_of :year, :in => "1980"..Time.now.year.to_s,
allow_nil=>true
will successfully validate the range but will not allow an empty input
field to be submitted. However, if :year is
2007 Jan 18
2
Conditional validates_inclusion_of execution problem
All,
I have a field that I''m validating with validates_numericality_of on as
well as validates_inclusion_of, like so:
validates_numericality_of :number_of_owners,
:only_integer => true,
:message => ''must be a whole number''
validates_inclusion_of :number_of_owners,
:in => 1..3,
2011 Feb 16
5
validates_inclusion_of with range on ruby 1.9
I found out today that Range#include? behaves differently on 1.9 than on 1.8 ( http://rhnh.net/2009/08/03/range-include-in-ruby-1-9 )
In order to deal with various edge cases, instead of just checking whether range.first <= value <= range.last, in ruby 1.9 include? steps through all the values in the range, checking for equality.
This is of course a lot slower - in my case, checking a date
2007 Mar 13
13
validates_inclusion_of disabling
Hello all.
I have a problem using validates_inclusion_of. I need to switch off some
validations during a migration period, is there a way?
I tried to use if, with a static method of one of my models, but the
behaviour is something strange
It seems that the static method should be in a string to be evaluated.
And the order of the elements in the if is counting...
:if => (:some_field
2009 May 22
1
[PATCH server] fixed smart pool 'save' regression.
The recent refactoring didn't work properly for new smart pools, so I've cleaned jup the parameter handling for the various pool 'create' actions.
Signed-off-by: Scott Seago <sseago at redhat.com>
---
src/app/controllers/hardware_controller.rb | 5 +----
src/app/controllers/pool_controller.rb | 6 ++++--
src/app/controllers/resources_controller.rb | 6
2005 Nov 25
2
acts_as_list with 2 fields in the scope
Hi Railers,
I''ve got a Categories table.
I want it to act as a list within the scope of the parent_id AND the
site_id.
Categories table :
id
label
site_id
parent_id
So, in my Category class, I have :
acts_as_list :scope => ''site_id = #{site_id} AND parent_id = #
{parent_id}''
The problem is that when I try to move_up a Category with a parent_id
that is null,
2014 Nov 24
3
[PATCH] v2v: -i ova: Remove incorrect warning for disks that have no parent controller (RHBZ#1167302).
Don't assume every disk <Item> has a <Parent> field. For floppy disks
this is not the case.
Thanks: Junqin Zhou
---
v2v/input_ova.ml | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index 95af2e5..9a9c10a 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -187,14 +187,17 @@ object
for i = 0 to
2006 Jun 19
3
Using set_primary_key breaks acts_as_tree with non-integer column
I just switched from using the standard "id" column into using my own
primary key and generating my own unique id for each record. But, this
breaks acts_as_tree.
Because my new primary key is not an integer, it breaks the SQL query
as follows:
StatementInvalid in PagesController#create
--------------------------------------------------------------------------------------
2006 May 07
3
Stupid newbie question
Here''s a request string which has a value I want to pull out from the
category array - parent_id.
Parameters: {"category"=>{"name"=>"Condiments", "parent_id"=>"1"},
"commit"=>"Create"}
How do I reference that subelement in the receiving script? I''ve tried
params[:parent_id]
2006 Apr 30
4
acts_as_ordered_tree
I need an ordered (sortable tree) and I just was thinking if somehting
like this is possible:
class Item< ActiveRecord::Base
acts_as_tree :order => "position"
acts_as_list :scope => ''parent_id = #{self.id}''
end
For my understanding mixing of two acts_as should be p?ssible, at least
in this case, right?
Unfortunatly the :scope is not working, I am not
2005 Sep 23
6
problem with acts_as_tree
Hi,
I''m using the latest gem version of rails under MacOS Tiger.
I was trying to use acts_as_tree as described in the rails book. So
I have something like:
class Category < ActiveRecord::Base
acts_as_tree :order => "title"
end
create table categories (
id int not null
auto_increment,
title
2006 Apr 09
1
select helper question
Hi there, I try to develop a medical application using ruby on rails.
There are many categories which can contain subcategories.
I defined the model like this:
class Category < ActiveRecord::Base
has_and_belongs_to_many :notes
belongs_to :parent_category, :class_name=>"Category",
:foreign_key=>"category_id"
has_many :sub_categories,
2005 Jul 25
2
acts_as_tree and traversing parent/child relationships
I am working on an Rails application that uses a pretty complex
category structure through out the site. I have defined a table to
house all the info and a FK to reference parents within the table
CREATE TABLE categories (
id int(11) NOT NULL auto_increment,
name varchar(50) NOT NULL,
parent_id int(11) default NULL,
constraint fk_category_id foreign key (category_id) references
2009 Feb 19
3
Associated child records not created on creation of a parent.
I am trying to create a record with association. Within the create
method, I would also like to pre-populate dependent (has_many) records
from a template in the database.
The child records are <u>mysteriously rolled back </u> if I insert
them in a loop. If I try to insert a single child record, it works.I
have read the books and tried to google my way out of this but am at a
dead
2006 Jun 16
1
sortable acts_as_tree with heirarchy
I''ve been stumbling on the tut at oriontransfer
(http://wiki.oriontransfer.co.nz/main/show/SortableTree)
I''ve got it working in a one dimensional list and I''ve got the drag and
drop working on children, but as can''t get it to save the tree.
Here''s my view:
<h2>Menu Prototype 2</h2>
<%= flash[:notice] %>
<ul