Displaying 20 results from an estimated 30000 matches similar to: "User defined model and validations?"
2006 Jul 27
0
Controllers, Models, and Validations...
Hello,
After listening to DHH''s 2006 RailsConf keynote, I decided to take a
leap on my current application and do a little more re-organizing to
make it more CRUD-based. As such, I ended up changing some things
around to get this (simplified):
User has_many :enrollments, :conditions => ''status > 0''
User has_many :schools, :through => :enrollments
User has_many
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations,
what is the ''best'' way to handle validations?
As an example:
class Student < ActiveRecord::Base
# some attrbutes like
# :name
# :grade
# relationships
has_many :students_assignment, :dependent => :destroy
has_many :assignments, :through => :students_assignment
has_many
2011 Jul 28
2
RSpec, shoulda-matchers and Rails model attributes validations
I was trying out RSpec framework in a project and got stopped doing the unit
test of a model. In particular, doing the test for the associations and the
ActiveRecord validations.
I started writing the validations but my tests didn''t look DRY at all.
Before refactoring the tests checked out and look for other people
solutions.
I found out shoulda-matchers and Shoulda (which if I
2006 Aug 09
1
Migrating a Field to External Model
I have a model Product with an attribute ''brand''. Currently it is a
simple attribute, however, I am migrating it to a separate model
Brand so that I can have other attributes with each brand. I created
the the model and created and ran the migration to create the new
table. So far so good. Then I created a separate migration to
transfer the data. The up method
2006 Apr 11
3
Validations and has_many :through (Join Models)
Hello again:
I''m hoping that somebody, anybody, can help with this question.
How do I make sure that records in a join model are unique?
Using the scenario outlined in Chad Fowler''s "Rails Recipies", number
16, "Many to Many Relationships Where the Relationship Iteself Has
Data".
Here are the tables:
create_table :magazines do |t|
t.column :title,
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:
2013 Sep 26
0
Devise Invitable and Validations -- what's the right way to do this?
Rails 3.2.14, Ruby 1.9.3, devise_invitable 1.1.8
I am trying to get invitations containing custom fields to validate their contents properly. I have tried the invite_keys hash route, as documented here: https://github.com/scambra/devise_invitable#model-configuration and unless I am doing something wrong with my Regexps, what happens is the fields are validated, but the error messages are
2006 Jan 15
6
PROPOSAL: Validations as Mixin
It seems to me that Validations are quite useful for many objects, even
ones having nothing to do with ActiveRecord.
Common examples are Contact Us forms, multi-step forms, web service
paramater validations, etc.
I took a look at the source for Validations, and it seems that it is
very independent from ActiveRecord. I caught only three depenedencies:
1. validates_numericy --> depends on
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
2009 Jan 16
3
rspec model testing - test on user defined validation- How do I test that the create failed.
I''m new to rspec and looking for way to test a validation I added to a model.
The test checks to see that if field1 has a value then field2 must be nil
and vice versa.
-------------------------------
When I did the rspec_scaffold it generated one test which worked
before :each do
@valid_attributes = {
:field1 = "value for field1"
:field2 = "value for
2009 Oct 27
5
Unwanted call to validates_associated
In my schema, a question has_many :answers. When the validations are
run on a question, and one of the answers is not valid, then i get
"Answers is not valid"
coming out of errors.full_messages. I don''t want this, i''m already
testing the validity of the answers and this is an ugly and
uninformative error message. It looks like it''s the message i would get
2006 Jul 07
0
2 sets of validations for one table possible?
Has anybody an idea if validations can be action or some variable -related?
I have 2 forms for 1 table and different kind of validations is required
for each of them.
Thanks
Miro
2010 May 21
0
Multiple Models one form and validations ... no transactions(mongo)
I am trying to setup a sigup form thats pretty much just like the
basecamp form. https://signup.37signals.com/basecamp/Plus/signup/new
I want to create
a User
a Studio
and a Subscription(chargify)
a Subscription belongs to a Studio and not to a User. User gets tagged
onto a Studio via an admin array.
Is there any way to do this all in one form and still get back
validation errors etc without
2006 Feb 02
6
How do I? Same Model, Different Controllers, Different Validations?
Hi all --
The simple question is: How do I set different validations for the same
Model, when accessed in different Controllers?
Here''s the scenario: I have a store/cart app, with a customer-facing
shopping cart, and a typical Admin side. The Admin side also has an
Order Entry component, where our staff can enter orders received by fax,
telephone, etc. Both the customer-facing cart
2006 Jun 05
3
ActiveRecord validations and FormBuilder
Hi,
I''m writing my own FormBuilder and I wanted to put an asterisk or
something next to any required fields. The Builder has access to the
AR object, is there any method I can call on the AR object that will
tell me whether or not a particular field is required? Failing that,
can I access the complete list of validations so I can look through
it for instances of
2006 Apr 01
3
Ignoring Validations In An Admin Tool?
I have the following validation on and ''Order'' model:
validates_presence_of :order_lines, :message => ''missing one or more
products.'', :on => :save
Ok, great. An order has to have products. Ok.
Problem is, there are some old orders that don''t have lines (don''t ask) and
in the admin tool we need to be able to work on these orders.
2006 Jun 18
1
plugings for date validations, email address validation & url validations in rails
Hi all,
Is there any standard plugin available for date validations, email address
validation & url validations in rails?
Thanks in advance,
Medha.
--
If not you then who.....
If not now then when......
-----------------------------------------------------
With Best Regards,
Medha.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
2009 May 27
0
Nested Forms with has_many associations with validations
I want to have a parent model that I can add child objects (via a
has_many association) using the rails 2.3 nested form syntax. However,
it seems like rails throws an error during validation of the parent
model if I have a validates_presence_of :parent_id defined in the child
model.
Is the only solution to this to remove the validates_presence_of
:parent_id? This seems like a hack-ish workaround.
2006 Feb 16
1
validations with associated object
Does anyone know if Rails is supposed to validate associated objects on
creation?
Say you have a User model, with has_many posts, and a Post model which
belongs_to user. Further, the Post model has a validates_uniqueness_of
:title.
u = User.find(1)
# this should pass
u.posts.create :title => ''my new post title''
# this should fail
u.posts.create :title => ''my
2006 Mar 23
1
validations.rb of ActiveRecord - bug or misunderstanding?
Either I''m not understanding how things are used, or this might be a bug
in ActiveRecord. I''m using version 1.13.2.
In my version of activerecord/lib/active_record/validations.rb (the svn
trunk version is browsable at
http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/validations.rb
), I have:
def update_attribute_with_validation_skipping(name,