error message

L

Lark Work

heey guyes, i need some help. i got this error message:
Error in application
NameError - uninitialized constant GreeterController
classpath:/./main.rb:51
classpath:/./main.rb:1:in `require'

this is my script:

48 begin
49 # Your application code goes here
50 require '/greeter/greeter_model'
51 GreeterController.instance.open
52 rescue => e
53 show_error_dialog_and_exit(e)
54 end

and the greeter_model is in a folder greeter in my Main.rb file.
this is my greeter_model:

class GreeterController < ApplicationController
set_model 'GreeterModel'
set_view 'GreeterView'
set_close_action :exit

def improve_button_action_performed
model.message = "But Swing with Monkeybars is awesome!"
update_view
end
end

i am doing a tutorial from monkeybars but i do everything right i know
that but i got that error (the only thing that i changed was <require
'greeter_controller' to require '/greeter/greeter_controller'> because
it otherwise while give a error messages that he can't find
"greeter_model"

so i hope i explained my problem whele, so that you guys could help me
:p

so please help me
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

heey guyes, i need some help. i got this error message:
Error in application
NameError - uninitialized constant GreeterController
classpath:/./main.rb:51
classpath:/./main.rb:1:in `require'

this is my script:

48 begin
49 # Your application code goes here
50 require '/greeter/greeter_model'
51 GreeterController.instance.open
52 rescue => e
53 show_error_dialog_and_exit(e)
54 end

and the greeter_model is in a folder greeter in my Main.rb file.
this is my greeter_model:

class GreeterController < ApplicationController
set_model 'GreeterModel'
set_view 'GreeterView'
set_close_action :exit

def improve_button_action_performed
model.message = "But Swing with Monkeybars is awesome!"
update_view
end
end

i am doing a tutorial from monkeybars but i do everything right i know
that but i got that error (the only thing that i changed was <require
'greeter_controller' to require '/greeter/greeter_controller'> because
it otherwise while give a error messages that he can't find
"greeter_model"

so i hope i explained my problem whele, so that you guys could help me
:p

so please help me
You say you changed "<require 'greeter_controller' to require
'/greeter/greeter_controller'>" but your code shows that you are requiring
'/greeter/greeter_model'
Try requiring the controller again instead of the model. If it complains
that it can't find the model, try requiring the model then requiring the
controller :) I think you are probably confused here, because you showed
code that defined the GreeterController, but your file is the greeter_model
file. I would expect the GreeterModel to be in the greeter_model file, and
the GreeterController to be in the greeter_controller file.


Regarding putting the '/' at the beginning, that is probably not right. A
leading slash means you are telling it to search from the root folder of
your system rather than the current dir of the file. I am surprised that you
didn't get a load error (perhaps MonkeyBars overrides require and doesn't
throw an error?). Anyway, if your file defines the GreeterController, but it
can't find the GreeterController, then your file must not have gotten
loaded.

As a sanity check, you can try replacing the 'greeter/greeter_model' with
the full path to the file for your system. So on my system, that might look
like '/Users/joshuacheek/deleteme/monkeybars-tutorial/greeter/greeter_model'
(I don't know Windows conventions, it might look very different if you are
on Windows).

If that doesn't fix the issue, then this is probably not the problem. But if
it does, then you just need to fix the require statements.

The general trick that I use to avoid errors when requiring files relative
to the current file:
require File.dirname(__FILE__) + '/greeter/greeter_model'

And if that doesn't work, maybe try:
File.expand_path( File.join __FILE__ , '..' , 'greeter' , 'greeter_model' )

Its disgusting to look at, but it should allow you to almost certainly find
the file that you are looking for (assuming it is in the correct place and
named correctly).
 
L

Lark Work

heey i love you man :p my problem whas that i had to require those other
file this is what it had to be:

require 'greeter/greeter_model'
require 'greeter/greeter_view'
require 'greeter/greeter_controller'
GreeterController.instance.open

so thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top