Summary of problem: my params hash is being made nil in my controller
without any reason that I can identify.
Everything was fine until I put this new code as the first lines of code
in my controller. But the block is not being executed because the puts
statement is not evaluated:
def calculate
if params[:id]
puts "in if statement"
@query = Query.where(:id => params[:id])
params = eval(@query[0].queryString).to_options
params[:query_end_date].to_options!
params[:query_start_date].to_options!
end
The controller then fails in the first line of the next block of code
(below), and the error is that I am evaluating a nil object.
if params[:entity_selection]=="ELB"
@instances_array = get_instances_array(params[:instance])
@grouped_elb_instances =
get_grouped_elb_instances(@instances_array, params[:instance])
else @instances_array = [] @grouped_elb_instances = []
end
If I comment out the first ‘if’ block, the controller works perfectly.
When I print the params before the if statement, it has a value, but for
some reason, it seems like the params variable is cleared from memory.
I have no idea what is happening.
But the block is not being executed because the puts
statement is not evaluated:
def calculate
if params[:id]
puts “in if statement”
Where are you looking for the output of the puts? On the web page?
In the log? On the screen of the server? In too many faces?
-Dave
–
LOOKING FOR WORK, preferably Ruby on Rails, in NoVa/DC; see main web
site.
Main Web S.: davearonson.com
Programming Blog: codosaur.us
Excellence Blog: dare2xl.com
@Michael: I’ll give this a shot soon and let you know what happens.
@Dave: I was looking for the output on the screen of the server. Should
I look somewhere else?
I’d have to post the entire controller to show you this, but when I
included my begin-rescue-ensure block (with the criminal if statement at
the top of the begin block), the error still happens, but not until the
ensure block…even though the params hash is referenced multiple times
before then.
I can post the whole controller if that would be helpful, but in any
case, I’ll see what happens with a raise statement in the criminal if.
Thanks man. I agree, that could be the problem. However, to test it out,
I commented out everything inside the if part of the ‘criminal if-else’
and no exception is raised. For example, the new code that works is:
def calculate
#Check if request is from a linked URL or direct request from site
puts "before if statement"
puts params[:entity_selection]
if params[:id]
#puts "in if statement"
#@query = Query.where(:id => params[:id])
#params = eval(@query[0].queryString).to_options
#params[:query_end_date].to_options!
#params[:query_start_date].to_options!
else
puts "in else"
puts params[:entity_selection]
end
So if it were the case that the params hash being mentioned could
overwrite it, then this version of the code would fail, right?
I appreciate the help. I’ll continue to try to figure this out. If this
doesn’t work, it could be anarchy out there. I’m worried.
I was responding to Fred’s suggestion that params was being overwritten
because it was mentioned in the if statement in the original code.
Forget my replies to Fred, do you have any idea why the params variable
is being made nil in the original post?
Use ruby-debug to break into the code and see what is happening. See
the Rails Guide on debugging if you do not know how to do that.
I was responding to Fred’s suggestion that params was being overwritten
because it was mentioned in the if statement in the original code.
Forget my replies to Fred, do you have any idea why the params variable
is being made nil in the original post?
leoncio caminha wrote in post #1022336:
return 3 is the right! the value dont change and never in into if,
because
you put false…its right
I was responding to Fred’s suggestion that params was being overwritten
because it was mentioned in the if statement in the original code.
Forget my replies to Fred, do you have any idea why the params variable
is being made nil in the original post?
I think perhaps you are thinking that a local variable created inside
an if block will disappear at the end of the block, so that the
original variable is restored. Wrong.