undefined local variable or method `public_class_methods'

10 views
Skip to first unread message

rellik

unread,
Apr 13, 2007, 3:51:14 AM4/13/07
to MOle Plugin
In a controller, I have several of the #after calls. Mostly they work
fine, but I am getting an error that I don't know how to get around.

## This works ##
def do_something
...
end

MyController.after (:feature=>:do_something) {}
## End ##

## This fails ##
def do_something
...
update_status()
...
end

def update_status
...
end

MyController.after(:feature=>:update_status) {}
## End ##

obviously it would be great to put the filter on the sub-method
(update_status). If 10 methods call update_status, I wouldn't want to
have to write 10 identical calls.

Is there a work-around for this?

By the way, the error I am getting from that second example is:

## Error ##
NameError (undefined local variable or method `public_class_methods'
for RequestsController:Class):
.//vendor/plugins/mole/lib/mole/module.rb:189:in
`find_public_class_method'
.//vendor/plugins/mole/lib/mole/module.rb:200:in `wrap'
.//vendor/plugins/mole/lib/mole/module.rb:125:in `after'
.//app/controllers/requests_controller.rb:569
.....
## End ##

Fernand Galiana

unread,
Apr 13, 2007, 10:27:02 AM4/13/07
to mole-...@googlegroups.com
Hello again,

   Could it be the case that update_status might be private/protected on the
   controller ? Currently the MOle will only attempt to locate public methods...

-Fernand

rellik

unread,
Apr 15, 2007, 2:02:31 AM4/15/07
to MOle Plugin
No, update_status() is public. If it were a method-privileges issue I
would expect a NameError from module.rb:201.

Looking at module.rb (the error is on line 189):
# Attempt to find singleton class method with given name
def find_public_class_method(method)
public_class_methods.each { |m| return m if m.name == method }
#189
nil
end

The problem is that self doesn't equal RequestsController, but instead
RequestsController:Class, which doesn't have the public_class_methods
function. I am having this issue on two methods. Both are sub-
methods, in that they are called by other controller methods, as
described in the first post.

On Apr 13, 9:27 am, "Fernand Galiana" <fernand.gali...@gmail.com>
wrote:


> Hello again,
>
> Could it be the case that update_status might be private/protected on the
> controller ? Currently the MOle will only attempt to locate public
> methods...
>
> -Fernand
>

rellik

unread,
Apr 15, 2007, 3:59:25 AM4/15/07
to MOle Plugin
I should clarify:
In my last post I said that if it were a method-privileges error, I

would expect a NameError from module.rb:201.

While I did in fact get a NameError, it was raised by module.rb:189,
not 201, which means that the error was raised by the system, not by
201: "raise NameError".

Fernand Galiana

unread,
Apr 15, 2007, 4:11:50 AM4/15/07
to mole-...@googlegroups.com
Patrick - I am updating the plugin as we speak. I have opted to remove
the code to try to detect static methods.

So could there be a typo on the method name ?

I think I have a similar case illustrated and working on the beast sample app ( you'll need to svn update... ), take a look and see if the setup is any different from yours...

Please keep me posted on this issue...

-Fernand

rellik

unread,
Apr 15, 2007, 5:22:05 AM4/15/07
to MOle Plugin
I updated to the latest version, but am having the same problem.

You asked if if might be a typo in the method name. Do you mean in
the :feature=><...> part?
I know that is right because I switch it to a non-error version when
I'm testing it:

### Code ###
def view
...
@foo = "FOO"
end

RequestsController.after(:feature=>:view) do |context, feature,
args, block|
Mole::DbMole.mole_it( context, feature,
context.session[:user], :args=>context.instance_variable_get(@foo))
#Mole::DbMole.mole_it( context, feature,
context.session[:user], :args=>args)
end
### End ###

The Readme has the following url for the beast demo:
svn://rubyforge.org/var/svn/liquidrail/plugins/mole/trunk/samples/beast
but that doesn't exist.

I found this, though: svn://rubyforge.org/var/svn/liquidrail/plugins/mole/samples/beast


The app failed to run. I guess I have to have beast installed to use
the demo? The database.yml file points to localhost, and the server
shows a page with "Oops! It looks like there was an error." Also, I
couldn't find any of the mole before/after calls in the controllers.

Maybe I downloaded the wrong thing? I don't see the similar case you
mentioned in your last post.


On Apr 15, 3:11 am, "Fernand Galiana" <fernand.gali...@gmail.com>
wrote:


> Patrick - I am updating the plugin as we speak. I have opted to remove
> the code to try to detect static methods.
>
> So could there be a typo on the method name ?
>
> I think I have a similar case illustrated and working on the beast sample
> app ( you'll need to svn update... ), take a look and see if the setup is
> any different from yours...
>
> Please keep me posted on this issue...
>
> -Fernand
>

rellik

unread,
Apr 15, 2007, 5:28:05 AM4/15/07
to MOle Plugin
Oops, I got confused which thread I was responding to :)

The beast errors are all applicable, but the code segment should be:

### Code ###
def save_req(req)
...
end

RequestsController.after(:feature=>:save_req) do |context, feature,


args, block|
Mole::DbMole.mole_it( context, feature,

context.session[:user], :args=>args)
end
### End ###

rellik

unread,
Apr 15, 2007, 5:30:47 AM4/15/07
to MOle Plugin
Fixed :)

turns out you have to put the mole_it call *after* the definition of
the function in the source file. I had originally had the sub-methods
at the end of the file, since they used to be private (before mole).

Reply all
Reply to author
Forward
0 new messages