Hey I feel like I’m missing something obvious,
I created an extension that adds some columns to the pages table, and
now I want to add some methods to the Page class.
I put this at the bottom of my Extension class
class Page < ActiveRecord::Base
def test_new_method
“hi”
end
end
And now I’m getting errors like:
undefined method children' for #<Page:0x2280638> undefined method
parts’ for #Page:0x2280638
Which leads me to believe that my version of Page is being loaded, and
the original version is not.
How do I get them both to load? what’s really going on here?
Also, can somebody tell why “logger” is not defined from my Extension
class
How can I access the logger?
thanks,
Jacob
Loren J. wrote:
class Page < ActiveRecord::Base
Should be:
YourPageClassName < Page
No, I don’t want to subclass page, I want to add methods to all pages.
I could directly edit page.rb but I’d like to limit my edits to remain
within the folder for my extension.
Jacob B. wrote:
Loren J. wrote:
class Page < ActiveRecord::Base
Should be:
YourPageClassName < Page
No, I don’t want to subclass page, I want to add methods to all pages.
I could directly edit page.rb but I’d like to limit my edits to remain
within the folder for my extension.
I am redefining page in the app/models directory of my extension
and in my extension definition I can explicitly load this verison of
page
like this:
load
“#{RADIANT_ROOT}/vendor/extensions/page_attributes/app/models/page.rb”
UGLY!!!
but that works…
Shouldn’t it just get loaded by default. What do I do to fix this?
It might be better to put your added methods in a module and include
them in Page inside the activate method of your extension, like so:
module NewPageMethods
def foo
“bar”
end
end
in your extension
def activate
Page.send :include, NewPageMethods
# …
end
Sean
Jacob B. wrote:
Shouldn’t it just get loaded by default. What do I do to fix this?
Put your methods in a module and mix them into page in your extension’s
activate method.
–
John L.
http://wiseheartdesign.com
Page.send :include, NewPageMethods
That’s the magic I was looking for thanks.