I have a search and filter table on my index.html.erb view. Depending on what is clicked in the view, I have to change the params. What is weird though, is that I get an error even if the if statement condition isnt met.
So for example, in my code, i have:
if params[:checkedA] != nil
params = someVar
end
if params[:checkedB] != nil
#run code
else
#run other code
end
When I just assign a random variable instead of params or get rid of the first if statement, it works.
if params[:checkedA] != nil
foo = someOtherVar
end
if params[:checkedB] != nil
#run code
else
#run other code
end
This also works
if params[:checkedB] != nil
#run code
else
#run other code
end
However, even if the if statement shouldn't run, it still fails. To test it, I tried
if 2 < 1
params = someVar
end
if params[:checkedB] != nil
#run code
else
#run other code
end
The error:
ActionView::Template::Error (undefined method `[]' for nil:NilClass):
1: <% if 2 < 1
2: params = someVar
3: end
4: if params[:checkedB] != nil
5: #run code
6: else
7: #run other code
app/views/quotes/quoteTable_js.js.erb:4:in `_app_views_products_product_table_js_js_erb
How can the if statement cause an error if it doesn't even run? Shouldn't that be the same as the statement not even being there?