Displaying 5 results from an estimated 5 matches for "class_def".
Did you mean:
class_dev
2006 Jun 26
5
How can I dynamiclly generate models?
...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 acts_as_commentable(options = {})
class_def = "class Comment < ActiveRecord::Base
set_table_name ''#{self.name.downcase}_comments''
belongs_to :user, :class_name=>''::User''
belongs_to :#{self.name.downcase},
:class_name=>''::#{self}'&...
2008 Jun 05
2
how to add a method without coding it directly into app?
...def self.included(base)
class << base
define_method :authenticate do |*a|
a.each do |meth|
if method_defined?(meth.to_s)
alias_method "__#{meth}__", meth
class_def(meth) do |*a|
@state.Back=@env.REQUEST_URI
return redirect(Login) if @state.blank?
or @state.user_id.nil?
send("__#{meth}__", *a)
end
end...
2007 Sep 18
2
Making attachment_fu polymorphic
...lent tutorial:
## http://clarkware.com/cgi/blosxom/2007/02/24
## 3. Give your Attachment_kung-ed Model the correct has_many for
polymorphism
## (I used: has_many :attachments, :as => :attachable);
## 4. Set the belongs_to and table_name methods to inside
Attachment_kung''s @class_def variable to
## match what you''ve done so far (the default is Attachment and
attachments). Also set
## the attachables hash in Attachment_kung''s intialize to match
the names of your model''s
## polymorphic attrubutes (the defaults are :attachable_id
and :atta...
2006 Jul 28
0
reserved words
...name)
end
def objeck(table_name)
klass(table_name).new
end
private
def class_name_from_table(table_name)
Inflector.camelize(table_name)
end
def define_klass(table_name)
tname = class_name_from_table(table_name)
class_def = <<-end_eval
class #{tname} < ActiveRecord::Base
set_table_name(''#{table_name}'')
end
end_eval
eval(class_def, TOPLEVEL_BINDING)
const_get(tname)
end
end
end
end
I need to somehow validate...
2005 Aug 19
13
Enumerations (again): Comments please
...self.reset
@@all = nil
end
protected
def after_initialize
freeze
end
end
def self.define_if_enumeration(const_id)
spec = @@enumeration_specs[const_id]
return nil unless spec
order = spec[:order] || ''position''
class_def = <<-END
class #{spec[:class_name]} <
BoilerPlate::Enumerations::EnumRecord
def self.all
return @@all if @@all
@@all = find(:all, :order => ''#{order}'', :conditions =>
#{spec[:conditions].inspect})
end
end...