On Sep 15, 10:42 pm, "Jonathan S." <[email protected]> wrote:
> 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
>

Local variables are tricky - merely mentioning them causes them to
spring into existence. For example if you run

if false
  x = 2
end

Then the local variable x is created, with value nil.

I think the same thing is happening here - a local variable called
params is being created, which is shadowing the params instance
method.

Fred



> 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.
>
> Any ideas?
>
> --
> Posted viahttp://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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to