Forum: Radiant CMS problem getting radiant-mental with custom extension working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-05 22:31
(Received via mailing list)
I moved my bits from my dev box; mac os x 10.4.9, ruby 1.8.5,
radiant(mental branch) r303 running on mongrel to my host
railsplayground.

On railsplayground, the server is running fcgi, but radiant is up and
working.  It is serving my pages just fine.  However, my trouble
starts with my custom extension that I wrote.  Again, it works
perfectly fine on my dev box, but on the hosting site it throws this
error when I try to access it from the admin portion of radiant:

Processing ApplicationController#index (for 70.190.32.209 at
2007-02-05 15:00:20) [GET]
  Session ID: 19c91a04a06891d8c0f825b6663d062f
  Parameters: {"action"=>"index", "controller"=>"admin/lectures"}


NameError (uninitialized constant Admin::LecturesController):
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:267:in
`load_missing_constant'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:453:in
`const_missing'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/inflector.rb:251:in
`constantize'
    /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/string/inflections.rb:148:in
`constantize'
    /vendor/rails/actionpack/lib/action_controller/routing.rb:1258:in
`recognize'
    /vendor/rails/railties/lib/dispatcher.rb:40:in `dispatch'
    /vendor/rails/railties/lib/fcgi_handler.rb:168:in `process_request'
    /vendor/rails/railties/lib/fcgi_handler.rb:143:in
`process_each_request!'
    /vendor/rails/railties/lib/fcgi_handler.rb:109:in
`with_signal_handler'
    /vendor/rails/railties/lib/fcgi_handler.rb:142:in
`process_each_request!'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in
`each_cgi'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in
`each'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in
`each_cgi'
    /vendor/rails/railties/lib/fcgi_handler.rb:141:in
`process_each_request!'
    /vendor/rails/railties/lib/fcgi_handler.rb:55:in `process!'
    /vendor/rails/railties/lib/fcgi_handler.rb:25:in `process!'
    dispatch.fcgi:24

My extension configuration is

  define_routes do |map|
    map.connect 'admin/education/:action', :controller =>
'admin/lectures'
  end

  def activate
    admin.tabs.add "Education", "/admin/education", :after =>
"Layouts", :visibility => [:all]
    Page.send :include, LecturesTag
    NoCachePage
  end


The funny thing is that on the first request (after the fcgi process
is restarted) works, but the second request gets this error.

I have double-checked all configuration issues with railsplayground
and verified that it works locally on my dev machine.  Anyone have any
hints as to what is going on?

I have even compared file by file between local and hosted and nothing
is different except the difference needed by fcgi on railsplayground.

Any help would be appreciated.

Jason
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-02-05 22:39
(Received via mailing list)
I suspect the difference is between development mode and production
mode.
However, I would double-check that your controller looks like so:

class Admin::LecturesController < ApplicationController
 # your actions...
end

Generally, in my extensions, I stay away from namespacing my controllers
and
get away with it by prefixing the route with /admin.  It makes things a
little easier.

Sean
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-05 23:43
(Received via mailing list)
Thanks for the help...at least now I have some thing to try.

Since you suggested two things to try, I tried all combinations and
here are my results

Scenario 1:  original route (no leading slashes) / namespace on
controller

define_routes do |map|
  map.connect 'admin/education/:action', :controller => 'admin/lectures'
end

class Admin::LecturesController < ApplicationController

dev:  broke...couldn't find controller
prod:  found controller, but couldn't find the views


Scenario 2:  original route (no leading slashes) / no namespace on
controller  (original configuration)

define_routes do |map|
  map.connect 'admin/education/:action', :controller => 'admin/lectures'
end

class LecturesController < ApplicationController

dev:  works correctly
prod:  cannot found controller


Scenario 3:  modified route (leading slashes) / no namespace on
controller

define_routes do |map|
  map.connect '/admin/education/:action', :controller =>
'/admin/lectures'
end

class LecturesController < ApplicationController

dev:  works correctly
prod:  cannot found controller


Scenario 4:  modified route (leading slashes) / namespace on controller

define_routes do |map|
  map.connect '/admin/education/:action', :controller =>
'/admin/lectures'
end

class LecturesController < ApplicationController

dev:  broke, cannot find controller
prod:  cannot find views

So, it looks like I need to add the Admin:: to my controller in my
extension for production only.  But, still not functional until I
copied my views from the extension directory to the main app
directory.

This is a complete hack, but it works as far as I can see...now is
there an explanation as to why this is happening?
Dc893f8ae12045dc71048a0c6a56fc01?d=identicon&s=25 Jacob Burkhart (igotimac)
on 2007-02-06 05:27
I too am having issues like this.

I solve them temporarily with explicit "load" calls in various places

i.e. at the end of page.rb in core I added
load
"#{RADIANT_ROOT}/vendor/extensions/page_attributes/app/models/page.rb"

My hope is that I'll be able to complete my extension with a bunch of
these hacks, and then go back and figure out a way to make it work
properly. I have a feeling the way that Radiant currently loads up all
extension code is insufficient, but until I have a completed working
extension I can't completely narrow the blame.  I suspect there are
changes that should be made in Radiant Core code, but I can't
rationalize them until I have an extension that demonstrates the need.

Also, I noticed sometimes routes.rb gets loaded befor routes defined in
my extension. Which leads to all URLs generated resolving to
site_controller.

(due to :    site.connect  '*url',  :action => 'show_page' )

So I actually added a line just before the site controller stuff so that
I would have a generic route for everything:
  map.connect 'admin/extensions/:controller/:action'
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2007-02-06 05:54
(Received via mailing list)
> So, it looks like I need to add the Admin:: to my controller in my
> extension for production only.  But, still not functional until I
> copied my views from the extension directory to the main app
> directory.
>
> This is a complete hack, but it works as far as I can see...now is
> there an explanation as to why this is happening?

Can't tell you what you've done wrong, as I can't reproduce it. Look at:

http://soxbox.no-ip.org/test/test_extension.tar.gz

If you can't see what you've done wrong, create the smallest possible
extension that you can to demonstrate your problem and file a ticket (at
http://dev.radiantcms.org/ - you'll need to register).

Dan.
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-06 06:14
(Received via mailing list)
I will keep trying things to keep narrowing it down.  At this point, I
cannot determine if it is my code in the extension, radiant, or my
hosting provider.

I will report back as soon as I know something.
61c2e937e608b1a57b6c7f9468a9455c?d=identicon&s=25 jsmorris (Guest)
on 2007-02-06 07:34
(Received via mailing list)
I took your example and integrated it with my site and it appears to
work.  Granted your index view is not as complicated as mine, but I
think I noticed a difference between this test extension and my
extension.

The test extension, has a structure of

app/controllers/admin/name_controller.rb
app/views/admin/name/index.rhtml

but in my extension, I don't have the intermediary admin folder, so I
think that is why it cannot find the views/controllers.

That is only difference I can see.  I loaded this extension in both my
local dev environment and my production site and it works.

Next, I want to edit my extension with what I learned to see if I can
remove the hack I put in.

Thanks for you help.

Jason
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-02-06 14:41
(Received via mailing list)
Jacob,

That sounds completely unnatural.  As DHH has said (paraphrasing) "doing
it
the wrong way should hurt".  I haven't had any problems with the way
Radiant
loads extensions -- routes and classes load in the right order. It seems
as
if what you want is to mix a module into Page, rather than redefining
the
class.  I'll be on IRC today if you would like assistance.

Sean
Dc893f8ae12045dc71048a0c6a56fc01?d=identicon&s=25 Jacob Burkhart (igotimac)
on 2007-02-06 18:10
> loads extensions -- routes and classes load in the right order. It seems
> as
> if what you want is to mix a module into Page, rather than redefining
> the
> class.  I'll be on IRC today if you would like assistance.
>
> Sean

Thanks for the offer Sean, what about this weekend?

It looks like I will take the approach discussed above of submitting
some "example" extensions that demonstrate my problems.


Sean, your idea to mix in a module work for adding methods to page, but
breaks for things like has_many and belongs_to ....
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-02-06 18:15
(Received via mailing list)
Jacob,

Regarding has_many and belongs_to, etc -- that is, class methods -- you
can
use the singleton class in your `activate` method,

class << Page
  has_many :widgets
end

-or- in the `included` method of your module do a class_eval,

def included(base)
  base.class_eval do
    has_many :widgets
  end
end

You could also use `send` to invoke the has_many method.  In other
words,
TIMTOWTDI.

Sean
Dc893f8ae12045dc71048a0c6a56fc01?d=identicon&s=25 Jacob Burkhart (igotimac)
on 2007-02-18 23:42
Sean Cribbs wrote:
>
> class << Page
>   has_many :widgets
> end
>
> -or- in the `included` method of your module do a class_eval,
>
> def included(base)
>   base.class_eval do
>     has_many :widgets
>   end
> end
>
> You could also use `send` to invoke the has_many method.  In other


The first 2 methods don't work at all.

I get
undefined local variable or method `inherit_from_page' for
#<Page:0x23a7f34>

Using the first 2 techniques, where I'm adding a:
      belongs_to :inherit_from_page, :class_name => 'Page', :foreign_key
=> 'inherit_from_page_id'


Using the third technique (explicit send calls) It actually "works" for
the first page load, and then fails on subsequent loads.


What I think is really messing things up is rails trying to
automatically load things.  I have rails in dev mode, and it reloads
changes to certain files, and not to other files.  I havn't been able to
figure it out, but my suspicions is that the way files are loaded at
startup is different from the way they are automatically reloaded.

I've been trying to look through the source attempting to figure out
exactly how extensions are loaded. If someone familliar with the subject
would hop on irc.freenode.net and talk to igotimac about it... I would
greatly appreciate any help.

thanks,
Jacob
Dc893f8ae12045dc71048a0c6a56fc01?d=identicon&s=25 Jacob Burkhart (igotimac)
on 2007-02-19 00:22
It's always the simplest solution isn't it...

I needed to do:

  def self.included(base)


Instead of

  def included(base)
This topic is locked and can not be replied to.