Andrew Cockayne
2008-Mar-17 23:38 UTC
NoMethodError (...occurred while evaluating nil.split)
I am getting a NoMethodError, with the following decription: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.split The error is raised on function call line of the ''.html.erb'' file. The function is present in the relevant ''helper.rb'' file and contains the following: [code] def splitBonusUnit(data) @returnValue = @data.split(/ /) return @returnValue end [/code] The ''data'' value passed into the function is confirmed to be "2 3"; when the code @data.split(/ /) is entered into the Ruby shell it works and expected and ["2", "3"] is returned. Why is this not working correctly when put within the Ruby on Rails web pages? If I take the ''split'' command out of the helper function, it also works correctly. My understanding of Ruby and Ruby on Rails is limited, as is likely obvious, so although I have found a way around it, I would appreciate a pointer to why it does what it does. Thank you. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Bush
2008-Mar-18 00:01 UTC
Re: NoMethodError (...occurred while evaluating nil.split)
Immortal Nights wrote:> def splitBonusUnit(data) > @returnValue = @data.split(/ /)Your parameter is "data", but you are operating on "@data". Make that: @returnValue = data.split(/ /) Also, if you are not referring to @returnValue elsewhere, then there is no need to make that an instance variable... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Immortal Nights
2008-Mar-18 00:10 UTC
Re: NoMethodError (...occurred while evaluating nil.split)
Well; something told me it would be rather simple. Yet, I tried so many things, but that. Thank you.> Also, if you are not referring to @returnValue elsewhere, then there is > no need to make that an instance variable...I agree, the variable was only created just on the off chance return on the split command was the issue. Again, thank you for your prompt reply. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---