A
A
Anton2016-01-27 18:29:45
Ruby on Rails
Anton, 2016-01-27 18:29:45

What is the error in the if condition?

Hello!
I prescribe:

checked: (params[:news][:news][category_ids] if params[:news][:news])

And I get the error:
# undefined method `[]' for nil:NilClass
The same error is caused by this:
<% if params[:news][:news] %>
     # тут что-то
<% end %>

How to fix it? We need to check the existence of the second news in [:news][:news].

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2016-01-27
@hummingbird

Solved the problem like this:
But this is something that really worries me. If there is another, more correct solution, I will be very grateful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question