# How does class loading work!?!

**URL:** <https://www.ruby-forum.com/t/how-does-class-loading-work/84413>\
**Category:** Radiant CMS\
**Created:** [February 4, 2007, 3:36am UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413 "2007-02-04T03:36:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![igotimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85f322/32.png) [@igotimac](https://www.ruby-forum.com/u/igotimac)\
**Post date:** [February 4, 2007, 3:36am UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413/1 "2007-02-04T03:36:00Z")

</div>

I’m getting more bizzaro behavior with my extension now relating to  
loading.

In this case, a routing declaration is working the first time, and then  
failing on the second try.

My partial calls:  
url\_for(:controller =\> ‘page\_attributes’, :action =\> :add)

the first time it loads, and things look ok. (after a fresh server  
restart)

But then when I go to another page and come back I get a:

No route matches {:controller=\>“admin/page\_attributes”, :action=\>“add”}

I’m defining my route by doing:

define\_routes do |map|  
map.connect ‘admin/page\_attributes/:action’, :controller =\>  
‘admin/page\_attributes’  
end

at the top of my extension (like the other ones do)

Can somebody please explain something about the magic that loads  
extensions.  
Apparently something is working when the extension is first loaded and  
then fails when it is re-accessed.

thanks,  
Jacob

---

<div class="post-metadata">

**Author:** ![igotimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85f322/32.png) [@igotimac](https://www.ruby-forum.com/u/igotimac)\
**Post date:** [February 4, 2007, 3:58am UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413/2 "2007-02-04T03:58:02Z")

</div>

> I’m getting more bizzaro behavior with my extension now relating to  
> loading.

my stacktrace

#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_controller/routing.rb:1252:in  
`generate' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:104:in`rewrite\_path’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_controller/url\_rewriter.rb:69:in  
`rewrite' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:522:in`url\_for’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_view/helpers/url\_helper.rb:27:in  
`url_for' /Users/igotimac/radiant_svn/mental/radiant/vendor/extensions/page_attributes/app/views/admin/page/_attributes.rhtml:116:in`\_run\_rhtml\_47vendor47extensions47page\_attributes47app47views47admin47page47\_attributes46rhtml’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_view/base.rb:326:in  
`compile_and_render_template' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:301:in`render\_template’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_view/base.rb:260:in  
`render_file' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:275:in`render’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_view/partials.rb:59:in  
`render_partial' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in`benchmark’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/1.8/benchmark.rb:307:in`realtime’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:26:in  
`benchmark' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:58:in`render\_partial’  
#{RAILS\_ROOT}/vendor/rails/actionpack/lib/action\_view/base.rb:287:in  
`render' #{RAILS_ROOT}/app/views/admin/page/edit.rhtml:125:in`\_run\_rhtml\_47app47views47admin47page47edit46rhtml’

Anybody know what the deal with the weird 47s is?

---

<div class="post-metadata">

**Author:** ![igotimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85f322/32.png) [@igotimac](https://www.ruby-forum.com/u/igotimac)\
**Post date:** [February 4, 2007, 4:02am UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413/3 "2007-02-04T04:02:46Z")

</div>

Jacob,

I am looking at the routes issue. The 47’s are part of the template  
compilation magic. You can ignore it.

adam williams

---

<div class="post-metadata">

**Author:** ![igotimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85f322/32.png) [@igotimac](https://www.ruby-forum.com/u/igotimac)\
**Post date:** [February 4, 2007, 10:21am UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413/4 "2007-02-04T10:21:07Z")

</div>

> I have just checked in some additional tests that show extension  
> routes working fine. I also created an extension, put in a custom  
> route, generated a link using url\_for, and have no problems. A couple  
> of comments below:

thanks Adam

I think things may be messed up in my case because I’m trying to add  
functionality to the page edit screen.

I did this by directly editing page/edit.rhtml (in core radiant) and  
adding:

\<%= render :partial =\> ‘attributes’ %\>

But that partial exists only in my extension.

This works, but I get the exception the second time \_attributes.rhtml is  
loaded (via a page edit).

I was thinking this would just be a temporary hack to make sure things  
work, and then later I would figure out how to enable the registering of  
a tab with the Page Edit interface just like you can register a new tab  
for the overall admin interface.

So, so far I’m stuck here, but maybe I’m taking the wrong approach to  
modify the page edit screen. Any other suggestions?

thanks,  
Jacob

---

<div class="post-metadata">

**Author:** ![igotimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85f322/32.png) [@igotimac](https://www.ruby-forum.com/u/igotimac)\
**Post date:** [February 4, 2007, 4:37am UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413/5 "2007-02-04T04:37:47Z")

</div>

Jacob,

I have just checked in some additional tests that show extension  
routes working fine. I also created an extension, put in a custom  
route, generated a link using url\_for, and have no problems. A couple  
of comments below:

On Feb 3, 2007, at 9:36 PM, Jacob B. wrote:

> My partial calls:  
> url\_for(:controller =\> ‘page\_attributes’, :action =\> :add)

Should that be :controller =\> ‘admin/page\_attributes’?

> the first time it loads, and things look ok. (after a fresh server  
> restart)

Production or development?

> ‘admin/page\_attributes’  
> end
> 
> at the top of my extension (like the other ones do)
> 
> Can somebody please explain something about the magic that loads  
> extensions.  
> Apparently something is working when the extension is first loaded and  
> then fails when it is re-accessed.

We are simply listening to Dependencies.clear, at which point we  
reload the extension classes explicitly, and have hooked into route  
reloading - which happens around the same time - so that we can get  
the extensions routes back in play.

aiwilliams

---

<div class="post-metadata">

**Author:** ![igotimac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85f322/32.png) [@igotimac](https://www.ruby-forum.com/u/igotimac)\
**Post date:** [February 4, 2007, 3:05pm UTC](https://www.ruby-forum.com/t/how-does-class-loading-work/84413/6 "2007-02-04T15:05:39Z")

</div>

Jacob,

You can redefine any view template in your extension without modifying  
the core. So if you wanted to override the page edit interface, just  
copy and modify app/views/admin/page/edit.rhtml to  
vendor/extensions/my\_extension/app/views/admin/page/edit.rhtml. That  
way you can keep your modifications separate from the core  
functionality.

Sean
