similar to: Multiple polymorphic belongs_to declarations

Displaying 20 results from an estimated 400 matches similar to: "Multiple polymorphic belongs_to declarations"

2007 Oct 18
4
Polymorphic Association?
Hi there- I''m a newbie to this board, RoR, and web development in general. So please forgive me if this is in the wrong place or if the solution is really simple... I''m trying to conceptualize the relationships between a series of models for a page creation function. What I''d like is to have a Content Page which consists of a series of Content Blocks. The Content
2008 May 19
6
obtaining table cell text data
I''m writing some code to subset a table based on the contents of particular columns. My event handler starts off like this: subsetChange: function(e) { var subset = $F(''subsetSelector''); var rows = $$(''.content-row''); rows.each(function(row) { var value = row.down(''.Platform_Category'').childNodes[0].data;
2006 Mar 17
6
Updated the xml code to be more object-oriented
I changed the code to be more prototype-esque, and created a class called XMLDoc. I may add more functionality to it later, hence the more generic name, but you do something like this to convert XML to a hash: XMLDoc = Class.create(); Object.extend(XMLDoc.prototype, { initialize: function (xmlDoc) { this.element = xmlDoc; }, asHash: function () { if (! this._xmlHash) {
2006 Mar 17
10
good javascript xml parser
Anyone know of a javascript function that will take an xml document and turn it into an associative array? Basically it would take something like this: <body> <item> <id>1</id> <name>Bob</name> </item> <item> <id>2</id> <name>John</name> </item> </body> And turn it into something like this: {
2006 Mar 23
4
XML parser fixed
Hi, I changed the XML parser who have been write by Greg (Gregory Hill) and changed some things. It did not work in IE and Safari and opera. I fixed some bugs. Now it works fine in IE, Safari, Firefox and Opera. /* --------------------------------------- */ XMLParser = Class.create(); Object.extend(XMLParser.prototype, { initialize: function (XMLFile, options) {
2006 Jan 23
5
validates_uniqueness_of :username, :if => !self.new_record?
Hi all I want users to register on my page. To register, they only have to deliver an email and a password. Then a link with an activation token will be sent to them, and after clicking the link the user sees a page where he should fill in further details, means: a username. My model looks like this: class Member < ActiveRecord::Base validates_presence_of :username, :if =>
2006 May 19
5
How to determine if an object has just been created
Is there a built-in way to determine if a model object has just been created (ie. this object was the one that was originally persisted)? I can''t see it anywhere in the AR code, but thought I''d check. I want something like: p = Person.create p.original_instance? # true Is this built-in or should I just patch AR? -Jonathan.
2008 Jan 31
4
reby-debug and rspec
How do I use the ruby debugger with a specific test (not the whole spec file)? I want to do something like this. $ rdebug spec/models/user_spec.rb -s "should error if not new_record" ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search.
2006 Aug 15
3
update or alter cart
I want to modify and update the items in the Depot - "display_cart". Since the cart is in a session, its a little hard to get at the data. I just want to create a way to change quantities, prices and recalculate. Has someone done this, and could you point me to the right direction. Thanks Chas -- Posted via http://www.ruby-forum.com/.
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
2010 Feb 20
23
Rails 3 possible bug in Routing
Hi, I just ran into this ActionController::RoutingError and just wanted to check if someone can confirm this as a bug in the Rails 3 beta gem. config/routes.rb contains: get ''login'' => ''session#new'' post ''login'' => ''session#create'', :as => :login GET /login works fine: Started GET
2007 Feb 08
5
a possible bug in Has_many :through using :soucre
I''ve been stumped on this for a few days and I''m not sure if it''s an error on my end or an actual bug. I have a system where I have workshops and users. Workshops have students, presenters, and troubleshooters. I wanted to represent this simply by using has_many :through with :source. Workshop has_many :presenters, :through =>:presenterships, :source=>:user
2006 Mar 16
10
Nubee Callbacks problem
I never want to alter a model(row). When a model has been changed i want a new copy to be created. What is the best way to implement this? I think using callbacks might be the answer. So model.save will create a new row, and leave the old one unchanged. Any ideas? I can easily implement this in the controller but i''d rather it be done transparently. Also errors should be passed back
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 Jan 08
3
Getting the current Action in the Model
Is it possible to get the current Controller''s action from within the Model? I have a situation where I want a piece of validation to run on edits, but not on new creates. Thanks, - Mark -- Posted via http://www.ruby-forum.com/.
2006 Feb 09
3
accessing associated models in a validate method
Why can''t I access an associated model in a validate method? I have some code that looks like the following: Models: class Product < ActiveRecord::Base has_many: upcs end class Upc < ActiveRecord::Base belongs_to :product def validate errors.add_on_blank(''upc'') unless product.new_record? end end Controller: def create @product =
2006 Feb 12
6
habtm doesn''t save old IDs
I''m sure I''m not getting something. I have Users, and I have Groups. Each User has_and_belongs_to_many :groups and each Group has_and_belongs_to_many :users. When I add a user, I want to apply a bunch of groups (like tags) to the user (manually, without acts_as_taggable). Here''s User#create: @user = User.new(params[:user]) @user.groups =
2006 Oct 13
3
Validation errors in has_one/belongs_to relationships.
I have two objects, QuoteInput and Insured. QuoteInput has one Insured and Insured belongs to QuoteInput. I don''t understand what I''m seeing. I assign an Insured to a QuoteInput. The Insured object has invalid data. I call save! on the quote input. QuoteInput has no validations. I expect two things to happen - 1) an exception should be thrown, indicating that there was a
2008 Aug 31
9
assigning collection values and exceptions
hi everyone, I''ve this code in my Report model: has_many :report_reasons, :validate => true has_many :reasons, :through => :report_reasons #, :uniq => true # :accessible => true def reason_attributes=(reason_attributes) reasons.clear reason_attributes.uniq.each do |reason| reasons << Reason.find_or_create_by_content(reason) end end
2006 May 31
7
How do you create a controller & view to create a list of objects?
I''m trying to figure out how to design a view and controller to work with a simple collection. I have a Foo that has many Bars, so here''s what I did: $ ruby script/generate model Foo $ ruby script/generate model Bar (Uncomment t.column, :name: :string in foo and bar migrations) (Edit Foo.rb and Bar.rb, add has_many :bars to Foo, belongs_to :foo to Bar) $ rake db:migrate $ ruby