This is old code (Rails v 1.1.6 - Ruby 1.8.5) that I am working with,
and don’t want to migrate it too to current version because it is not
The code is almost exactly as cited above, just have the column names
The error code tells me that
NoMethodError (undefined method
province' for nil:NilClass): /path/file.rb:302:inset_no’
So I look on that line, in the set_no definition, which is where I was
trying to call this line
if @my_names.province == “XX”
province is one of the column names that is returned from the
Does this make any more sense now ? I have been through many attempts to
resolve this, and can work with parameters, etc but with DB returns it
seems I am missing something.
Colin L. wrote in post #1083450:
On 7 November 2012 20:07, Jeff L. [email protected] wrote:
I am new to the language and trying to add a couple of simple tests on
user input, followed by a DB query, then using the returned values
(where the problem lies)
I first run a find_by_sql similar to this
@my_names = modelname.find_by_sql
I know this is not part of your question, but as a newcommer to rails
I think it is very unlikely that you should be using find_by_sql.
There are not many situations that this is necessary, there is almost
certainly another way. You might like to ask about this in another
thread to see if there is a better way.
session[:whatever] = @my_names.column_name
but am unable to perform a if construct that looks like
if @my_names.column_name == “TEST VALUE”
I keep getting an undefined method error when I try to run the code.
Thanks very much in advance for any assistance with this.
Show us the actual code and the full error message please. First look
carefully at the error and try to interpret it, often the clue is in
the message but may not be initially obvious to a newcommer.
Finally, if you have not already done so, I recommend working through
a good tutorial on rails. railstutorial.org is good and is free to
use online. Make sure that you use a tutorial for rails 3 and that
you use exactly the right version of rails.