Displaying 20 results from an estimated 4000 matches similar to: "polymorphic has_many from ActiveRecord::Base????"
2008 Jan 08
1
add comments to ALL models (ie automatically add has_many)
I have the acts_as_commentable and a bunch of others added to pretty
much every model, is there a way to automaically add these to EVERY
model ?
I tried the following but it fails with an error...
ActiveRecord::Base.class_eval do
has_many :notes, :as => :model_with_notes, :dependent => true
end
fails with....
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/
2010 Aug 10
2
undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin
Hi, i am using Savage Beast 2.3 plugin for the forum and i got and
error
undefined method `has_many'' for Object:Class
C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
9:in `included''
C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
7:in `class_eval''
C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
7:in
2006 Jul 26
4
Execute code when an inheritance happens, or disabling STI
I am trying to inherit from a ActiveRecord class defined in a plugin.
The problem is that ActiveRecord thinks I am doing an STI and is looking
up a table that doesn''t exist.
Currently, I have a method in the parent class that looks like this:
def self.fix_table_name
class_eval do
set_table_name(Inflector.tableize(self.to_s))
end
end
The problem is that this method
2006 May 05
1
class_eval in ROR''s attribure_accessor.rb
hi,
here is a snippet code in ROR''s attribure_accessor.rb. the usage of
class_eval is different with "class_eval(string, <, file, <line>>)"
somewhat,
i don''t understand this usage, who can explain it more detail to me?
def cattr_writer(*syms)
syms.flatten.each do |sym|
class_eval(<<-EOS, __FILE__, __LINE__)
unless defined?
2009 Feb 02
2
ActiveRecord::AssociationTypeMismatch (User(#54754560) expected, got User(#54510280))
i keep getting this AssociationTypeMismatch error. i think this could
be a bug related to ruby/rails when using mixins. heres a short
version of my code:
# user.rb
require ''friend_invitation''
require ''friendship''
class User < ActiveRecord::Base
include FriendInvitationUser, FriendshipUser
...
end
# friendship.rb
...
module FriendshipUser
def
2008 Nov 19
3
Mock today
In some of my unit tests, I find the need to set today to a different
value than the actual today. For example, to test the model method
"balance_of_today", which takes no argument, I want to have Date.today
be a specific date for the purpose of testing. In other words, I want
to do something like this:
mock_today(Date.new(2008, 2, 1)) do
... test code...
end
My implementation for
2012 Jul 25
0
Rails3-default_scope throws exception: undefined method abstract_class? for Object:Class
I would like to apply logical delete in my application(Instead of
permanently deleting a record just have been marked as deleted). I have
Added *available* column to all tables with default value *true*. Now I
want common place to write the following code for all models.
1.
Write the instance method which make ''available'' column value false when user clicks on
2011 Dec 03
1
ActiveRecord Abstract class
Hi, I was trying to create an abstract class and a subclass which
inherit that abstract class.
However, seems like I cannot instantiate the subclass too. Below is my
code:
//abstractclass2.rb
class Abstractclass2 < ActiveRecord::Base
self.abstract_class = true
end
//subclass.rb
class Subclass < Abstractclass2
end
When I test drive it in rails console, I got the following error:
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2005 Dec 29
3
Why do plugins use class_eval?
I''m writing my own plugin and all the plugins I''ve seen use class_eval in the
method that is called in the including module. For example:
http://wiki.rubyonrails.com/rails/pages/HowToWriteAnActsAsFoxPlugin
module Foo
module Acts #:nodoc:
module Fox #:nodoc:
def self.included(base)
base.extend(ClassMethods)
end
# declare the class level
2006 Jun 26
5
How can I dynamiclly generate models?
I am trying to write a plugin, ''acts_as_commentable'', for my models -
Image, Book, Music and so on, I do not want to use polymorphic
association, so very model should have its own comment class.
Here is my code
acts_as_commentable.rb
module Commentable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def
2011 Jul 06
5
Monkey patching a gem (rails_admin, with Rails 3)
Hi.
I''m trying to monkey patch the rails_admin gem.
First, I tried to add a file in config/initializers containing:
RailsAdmin::MainController.class_eval do
def get_sort_hash
CODE HERE...
end
end
It was only loaded once, and then the method from the gem was always
executed instead of mine.
I also tried to add the code in lib/ with the correct line in
config/application.rb to load
2005 Sep 11
3
Extending ActiveRecord::Base
Hey everyone,
I''m interested in extending ActiveRecord::Base. I have a special
"easier" find function that I want to include in all classes.
How can I include this in all classes?
Can I just create a model object that does something like this:
class ExtendedAR < ActiveRecord::Base
def self.special_find
...
end
end
and then all my other classes
2006 May 21
3
has_many :through with a polymorphic join
Hi,
Four tables: users, user_counties, uk_counties and us_counties.
Each user has many counties, and each county has many users, so I
decided to make user_counties a polymorph, so it can have counties
from different countries (each country requires a completely different
set of tables with a completely different set of properties, that''s
why there''s one table for uk_counties and
2006 Apr 21
3
polymorphic,has_many through can not work?
Josh Susser tells in his blog that the opposite direction of polymorphic
will get into trouble together with has_many through.
This is the url:
http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through
I do that according to Josh Susser''s procedure:
class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :taggable, :polymorphic => true
belongs_to
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2006 Jul 31
0
Polymorphic has_many association through a belongs_to
Hi,
Let''s say I''ve the following Models and their relative associations:
Seat
----
belongs_to :booking
Booking
-------
has_many :seats
has_many :debits, :as => :chargeable
Debits
------
belongs_to :chargeable, :polymorphic => true
Why
>> seat.booking.debits
nil
while
>> Booking.find(seat.booking_id).debits
[]
?
Thanks.
Cheers,
Marco
2007 Dec 20
0
polymorphic has_many :through Vs Inheritance
Hi everyone.
Ive part of a project that I need to refactor, and im having some
difficultly deciding which path to take. Perhaps someone can help, I
think its primarily a design question.
A Spec consists of many Nests and many Parts. Nests contain Parts.
Here''s what I have, which works well currently:
---------------------------------------------------
class Spec <<
2007 Apr 30
2
has_many :through polymorphic
Hi All,
I have the following arrangement:
class PickAndPackRequest < ActiveRecord::Base
has_many :transactions, :as => :request
has_many :postings, :through => :transactions
end
class Transaction < ActiveRecord::Base
belongs_to :request, :polymorphic => true
has_many :postings
end
class Posting < ActiveRecord::Base
belongs_to :transaction
end
But when I ask for
2007 Apr 21
0
has_many / has_one polymorphic with conditions
I''m looking for a way to make this work (I think the code is more
explanatory at this point):
## THIS WORKS
has_many :images, :as => :imageable, :dependent => :destroy, :order =>
''position ASC''
# @product.images => #
## THIS DOESNT
has_one :featured_image, :as => :imageable, :conditions => "position =
1"
# @product.featured_image =>