Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

ruby - Adding a method to a Rails ActiveRecord class -


in plain ruby, works fine:

class testsuper   def foo     puts "in testsuper.foo"   end end  class testclass < testsuper   def foo     super     puts "in testclass.bar"   end end  class testclass   def bar     puts "in testclass.bar, second definition"     puts "calling foo:"     foo   end end  t = testclass.new t.foo t.bar 

i can call foo() , bar() on testclass instance , expect:

in testsuper.foo in testclass.bar in testclass.bar, second definition calling foo: in testsuper.foo in testclass.bar 

however, when try similar in rails migration, errors:

#### my_model.rb #### puts "in my_model.rb" class mymodel   has_many :foo end  #### my_migration.rb #### puts "in my_migration.rb" class mymodel   def bar     foo.each{ |f| f.baz }   end end  class mymigration < activerecord::migration   def self.up     mymodel.find(1).bar           end    def self.down     # not applicable   end end 

the first problem mymodel.find() disappears unless explicitly have extend activerecord in my_migration.rb. otherwise, drops superclass.

if that, error on foo call in mymodel.bar().

if comment out class (re)definition in my_migration.rb, find() , bar() both work fine.

during course of debugging, added puts statements see when each file & class being executed. appears my_model.rb doesn't loaded if mymodel defined (which i'm doing in my_migration.rb).

so: why happen in rails, , how can work around it?

theory #2: @ top of migration

require 'app/models/my_model' 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -