Displaying 20 results from an estimated 1000 matches similar to: "(2.3.5) removing validations"
2011 Feb 28
1
(2.3.5) removing validations
Today I tried to remove (actually overwrite) a validation from a model,
from within a plugin.
This was the original validation:
validates_length_of :login, :maximum => 30
This was the only code I could come up with to replace it:
def self.included(base)
base.class_eval do
@validate_callbacks.delete_if { |callback|
begin
# Sorry, only way to remove
2006 Feb 09
0
Validations with conditions (:if)
Hello all.
I have a users table (it has three columns: name, password, active) and
I want to validate it''s name column only if the active column is set to
true. To do this I use the :if statement in all my validations, but it
doesn''t work. I''ve tried many ways to do this (using Symbols, Proc''s or
methods) and nothing works (using Symbols doesn''t
2009 Feb 04
2
delete_if does not work on associations
I tried to user delete_if on an association:
class Group < ActiveRecord::Base
has_many :memberships, :dependent => :destroy
has_many :users, :through => :memberships
...
end
This is the controller method, trying to use delete_if. Although some
elements are removed (s2 < s1), the save method does not update the
association.
def intersect_or_remove_group
other_group =
2011 Apr 18
2
acts_as_commentable validations
Hi all,
I recently started back up with Rails and things are going well up until
now.
I''ve set up acts_as_commentable in my Post model and it''s working great.
Problem is users are able to create a "blank" comment. I''ve added the
following validations in the comment.rb file generated by
acts_as_commentable to limit the comment length:
[code]
2007 Oct 13
4
Chapter 9
Hello,
I''m currently stunk on this issue for few days and I do not know how
to get it fixed.
The system always raises this error message :
order is closed
and here is my order.rb:
class Order < ActiveRecord::Base
include ActiveMerchant::Billing
before_validation :set_status
attr_protected :id, :customer_ip, :status, :error_message, :updated_at, :created_at
attr_accessor
2009 Sep 19
1
validations on a field
hi, i have a model with 2 validations on a field
example:
validates_presence_of :email
validates_length_of :email, :within => 6..100 #r@a.wk
validates_uniqueness_of :email
validates_format_of :email, :with =>
Authentication.email_regex
if i do the submit of form for a new object of the model with a blank
mail
i receive 4 errors.
In this case i want receive
2006 Aug 17
2
validates_length_of with char field
I am new to ruby/rails and am having a problem with validates_length_of.
It seems to work fine on a varchar field, but when I try it on a char
field the extra characters are silently truncated and the message
appears that the record was successfully updated.
How can I get my app to produce my error message instead? I''ve tried
various variations, but here''s one of my tries:
2012 Aug 14
3
validates_format_of :message not working, validates_length_of :message is working
I''m using validates_format_of and the validation I want to do works, but I
can''t get an error message to be displayed if the data is invalid:
validates_format_of :mobile, :with => /\A[\+0-9]+\Z/, :message => " - Wrong"
I have another validation some where else that does display the error
message: " - Name is too long"
validates_length_of :name,
2005 May 29
0
validates_length_of && validates_presence_of: Duplicate error messages?
validates_presence_of :login , :on => :create, :message => "Please
enter a login."
validates_length_of :login, :within => 3..40, :message => "Login must
be a minimum of 3 characters."
Right now if the login field is left blank, both these errors get
thrown. I assume that setting a conditional for the first one if the
second one is thrown, something like
2006 Jan 07
3
user engine question
I''ve created an array of hashes in UserController#initialize to describe
a menu:
@menu_array = [
{:menu => ''home'', :controller => ''home'', :action => ''send_home''},
{:menu => ''user list'', :action => ''list''},
{:menu => ''login'', :controller =>
2006 Sep 25
2
@article.article_groups.delete_if... Dosn't work!
If I try:
@article.article_groups.delete_if {|x|
x.group_id == x.group_id
}
It does nothing.
If I try:
articletmp.article_groups.each{ |x|
@article.article_groups.delete(y)
}
It deletes some of the groups.
@article.article_groups.clear
works.
Why dosn''t the to first examples work as expected??
Do I have to put groups I don''t want to
2007 Mar 29
4
validates_length_of not working with :if ?
Hello,
I''m trying to cut down the errors if the guy already getting the empty
nickname, so he doesn''t get anything about the nickname is short.
validates_presence_of :nickname
This below is not working ?
validates_length_of :nickname, :within => 4..40, :if => Proc.new {
|user| user.nickname.length > 1 }
nor this one below?
validates_length_of :nickname, :within
2005 May 04
1
Conditional validations
I''ve been working with the problem that Joe Hosteny has been talking
about on this list and on the tickets he''s posted
(http://dev.rubyonrails.com/ticket/1196) and have come up with a
tentative solution that I''d like to bring up here.
What if we use a "conditional" parameter in the validates_* methods?
Here''s how it would look like in practice:
2006 Nov 04
0
@article.article_groups.delete_if... Dosn''t work!
If I try:
@article.article_groups.delete_if {|x|
x.group_id == x.group_id
}
It does nothing.
If I try:
articletmp.article_groups.each{ |x|
@article.article_groups.delete(y)
}
It deletes some of the groups.
@article.article_groups.clear
works.
Why dosn''t the to first examples work as expected??
Do I have to put groups I don''t want to
2006 Nov 04
0
Validations ignoring :allow_nil => true
I have an address model and am doing some validations. One of them seems
to ignore :allow_nil => true. If I leave the phone input blank, I get
it back with a "too short" error. Here''s the relevant parts of the model:
1. class Address < ActiveRecord::Base
2.
3. validates_length_of :phone, :in => 7..10, :allow_nil => true
4.
5. before_validation
2006 Mar 17
0
validations using acts_as_taggable
Can anyone provide me an example of how they are displaying validation
errors when saving a tag using Demetrius''s (not DHH''s) act_as_taggable
plugin?
For example, the tag model has a
:validates_length_of :name, :in => 1..30, :too_long => "Tag name too long -
max 30 characters", :too_short => "Tag must have a name"
If a user inputs a tag longer than
2005 Nov 26
0
Model warnings along with Validations
Hi railers,
Is there a simple method to extend Active Record to have similar
functionality as the validate functions e.g.
validate_on_find
validates_acceptance_of
validates_each
validates_format_of
validates_length_of
validates_uniqueness_of
etc...
but only report warning on model attributes instead of errors().
I would like to save the model if there are warning and if the model is
invalid
2005 Jul 07
3
NameError Exception
Ruby/Rails n00b here so go easy on me...
I''ve been wracking my brain trying to figure out what is wrong here.
I''ve checked all my models for the appropriate belongs_to, has_many,
etc. I''ve checked to make sure I''m using singular and plurals in the
right spot. I''ve checked my syntax around all my "within"''s and nothing
seems to fix
2006 May 26
4
shouldn''t this work? - session[:array_of_objects].delete_if {|x| x.id == params[:id]}
I am saving an array of active record objects (college courses) in the
session as session[:course_list]. This is the cart for a registration
controller.
If a student chooses to delete the course from the list I get the :id
as params[:id].
However if I do
session[:course_list].delete_if {|x| x.id ==params[:id]}
does not work.
session[:course_list].delete_at(idx)
works. Ocourse to do this I have
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