similar to: Changing accessor list order

Displaying 20 results from an estimated 10000 matches similar to: "Changing accessor list order"

2007 Jun 18
4
polymorphic validation
Hello I have 2 models. link.rb has_many :categories, :as => :categorized validates_presence_of :name, :url, :created_at, :category category.rb belongs_to :categorized, :polymorphic => true validates_presence_of :name Everything seems to work. I select my category from a select tag. The problem is i don''t know how to validate if category is for example empty (nothing in a
2008 Oct 09
2
has_many validation the Rails way
Okay, this is something I run into a lot and don''t really have a great solution. Here is a simple example: class Blog < ActiveRecord::Base has_many :posts validates_presence_of :name end class Post < ActiveRecord::Base belongs_to :blog validates_presence_of :name validates_presence_of :blog_id end Now, if I want to create a blog and post at the same time I
2007 Jun 21
1
Validation Through Multiple Models from one Form
Hey All, I have a form that submits data to multiple models. I have class Man < ActiveRecord::Base has_many :notes has_many :contacts validates_associated :contacts, :notes validates_presence_of :first_name validates_presence_of :last_name class Contact < ActiveRecord::Base belongs_to :man validates_presence_of :contact_info class Note < ActiveRecord::Base
2009 Aug 05
1
[PATCH server] associated nics w/ network base class as it is in the db
fixes regression bug that got recently introduced --- src/app/models/network.rb | 2 ++ src/app/models/physical_network.rb | 2 -- src/app/models/vlan.rb | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app/models/network.rb b/src/app/models/network.rb index a4b1b8b..89f9876 100644 --- a/src/app/models/network.rb +++
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
2010 Jun 08
9
[Rails Heroku] Problem with saving object (on heroku hosting)
Hi All, I have some strange problem which appears only on heroku hosting 2.3.5 default stack (not on my local computer) I have some models. Here they are: class Contact < ActiveRecord::Base belongs_to :user belongs_to :type, :class_name => "ContactType", :foreign_key => "type_id" validates_presence_of :name, :on => :create, :message =>
2006 May 28
3
Validating Foreign Key
Howdy, I''m a Rails beginner working on my first significant project with RoR. I''m trying to figure out how to validate a foreign key (you know, make sure the row actually exists.) However, validates_associated doesn''t seem to be what I want to use, nor does it work... -- BEGIN -- class City < ActiveRecord::Base has_many :schools belongs_to :state
2009 Jan 09
3
What is wrong with validates_presence_of :my_association ?
Category.has_many :products Let''s say a product must belong to a category. I know it is recommended to do the following: class Product validates_presence_of :category_id end But, as we all know, this is a pain for new records, meaning what if the associated category is a new record? I''ve been meaning to ask this, but what''s wrong with doing the following: class
2006 Mar 15
3
Self-referential join model does not work
I have been trying to model a labeled graph using ActiveRecord (trunk version). Basically, I have a ''Node'' model which represents a node linking to other nodes. Links (aka edges) are labeled (i.e., have a ''label'' attribute and other behavior). Thus I decided to model edges as an ''Edge'' model and use a ''has_many :trough''
2007 Dec 22
3
collection_select validation problem
I''m trying to assign a parent foreign key value using collection_select from my child "new" form. The problem I''m having is if I do not make a selection, I get the following error instead of the Rails validates_presence_of error: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating
2006 Mar 18
4
Accessing overridden method
I have two model classes: class Item < ActiveRecord::Base belongs_to :channel, :counter_cache => true validates_presence_of :channel end class Channel < ActiveRecord::Base has_many :items, :dependent => true end In the Channel controller I have variable channel.items, an Array of Items. I would like to use the Array find method. However, channel.items.find() is a Rails
2005 Oct 26
2
validates_associated ... doesn't
Hi, I think I''m missing some fundamental information here so hopefully someone can help me. I have a model Club which has many members, members of course belong to a Club. I''d like to ensure that when a members is saved (saved/created/updated) only valid club_id''s are accepted. I have a Club model (simplified) like this: class Club < ActiveRecord::Base
2006 Mar 25
3
validates_presence_of validation order?
I have a form with 3 fields: user_id, email and password. All 3 fields are required, so I have a "validates_presence_of :user_id, :email, :password" in my model. Works, but the validation errors show up in a different order than I specificed in the validates_presence_of statement. Is there a way to specify the order in which the validations (and corresponding error messages) should
2006 May 23
1
Validating a required relationship.
Hello, I''m not sure if I''m missing something blindingly obvious here. All the relationships that Rails comes with assume 0..n, yes? It''s not a strict 1 to 1 or 1 to n because it''s optional. My question is this - What is the best way to implement a required relationship? For example, if I require that a comment is made by a user (a user has many
2009 May 25
4
after_create and has_one association bug?
Hello, I''ve come across an issue that I''m sure is a bug when using after_create with a has_one association, but I''m not 100% certain if I''m missing something. This is pretty much exactly the code I''m using. Two simple classes (Account and Contact) and I create the contact after I create an account (via after_create). I''m not passing in a
2006 May 26
7
migration with required data
I''m working on a bugtracker application in rails. I have a Bug model and I want to add a Priority to the mix. A Bug can have one priority. I generate a Priority model, modify my Bug model with a belongs_to :priority and create my migration like so: class CreatePriorities < ActiveRecord::Migration def self.up create_table :priorities do |t| t.column :name, :string,
2006 Dec 05
4
has_many with :uniq not working for me
Hi all, I have a relationship (no really!) class RiskMatrix < ActiveRecord::Base has_many :severities, :order => :position, :uniq => true end class RiskFactor < ActiveRecord::Base belongs_to :risk_matrix validates_presence_of :descriptor, :example validates_uniqueness_of :descriptor, :example, :scope=> :risk_matrix_id end class Severity < RiskFactor
2010 Aug 28
1
validates_uniqueness_of missing in rails 3.0 rc2?
Has anybody noticed validates_uniqueness_of missing in rails 3.0 rc2? I''m not sure if this is a bug or I''m just doing something wrong. Here''s what I''m doing. Class 1: class Title < ActiveRecord::Base validates_length_of :language, :is => 3 validates_uniqueness_of :language, :scope => :book_id validate :language,
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated... Let''s say I have: article belongs_to author But for whatever reason, I want an article to also be written anonymously and therefore not require an author. Then I have: Article: belongs_to :author validates_associated :author But I DON''T have validates_presence_of. What I want to do is validate that an author is valid --if it is
2006 Jan 09
1
Saving an upload
I am creating a database for movies (films) and television shows (shows) that will have has_and_belongs_to_many relationships with the pictures table. CREATE TABLE screenshots ( id serial NOT NULL, filename character varying NOT NULL, content_type character varying NOT NULL, primary key (id) ); CREATE TABLE films ( id serial NOT NULL, name character varying NOT NULL,