mardi 1 décembre 2015

Rails checkbox array choose nothing

I m getting the computer_ids of user like that

<%= check_box_tag "user[computer_ids][]", computer.id, @user.computers.include?(computer) %>

If I choose at least one from checkbox array, that's fine. But if I did not choose any thing it give me an array like that

undefined method `[]' for nil:NilClass

That's because there is no parameter comes. I did not find a solution. The relation is habtm

I'm try to control it is empty or not

if ( !(params[:user][:computer_ids].empty?)  )




Aucun commentaire:

Enregistrer un commentaire