1

I am making a rhodes application for iPhone. I am getting "undefined method `[]' for nil:NilClass" exception while the executing the line of code given

url_string = url_for(:action => :my_callback)

"MyScanner < Scanner" is my class and the Scanner class is declared like "Scanner < Rho::RhoController". For the Scanner < Rho::RhoController I have added "require 'rho/rhocontroller'"and "require 'helpers/browser_helper'" and also included "include BrowserHelper". I am new to Rhodes. Any one can help to find the reason for this exception.

Thanks in Advance :)

Augustine P A
  • 5,008
  • 3
  • 35
  • 39
  • Try to use a different name than Scanner. There's already an API with that name in RhoElements and this can generate the issue you see. – pfmaggi Sep 13 '13 at 22:10

1 Answers1

0

I'm also starting with Rhodes, and it can be highly confusing. Consider the following:

You will find that the Rho module is composed within several files in the rho folder, which is why you see includes such as rho/rhocontroller, a necessary include for subclassing Rho::RhoController.

helpers/browser_helper won't you out here, because it only contains methods for handling platform issues. url_for is actually defined in rho/viewhelpers, which is already included by rho/rhocontroller, meaning you should be able to use it by default in RhoController subclasses.

Without more code there is no way to tell what your exact issue is, but it probably has something to do with metaprogramming, the feature of Ruby that makes it THE most awesome language but also highly complex. I'm still learning how it all works, and will for quite a while.

Maybe these articles would be helpful in solving your problem:

Steve Benner
  • 1,679
  • 22
  • 26
  • Thanks Steve. Will go through the articles and hope I could find the reason behind that. – Augustine P A Aug 19 '13 at 08:26
  • I can also mention that recently I have encountered this error a few times (it's very common) when I haven't set a variable properly. For example, if you have in ERB code something like `@posts.each` and there are no posts, you will receive this error if you haven't initialized the variable in your controller. So one thing to pay close attention to logic surrounding the instance variables. Hope that is helpful. – Steve Benner Sep 03 '13 at 06:20