collection_select, undefined method `map' for nil:NilClass

前端 未结 2 1494
情书的邮戳
情书的邮戳 2021-01-19 17:25

I added in the @user = User.new line to make sure it isn\'t nil. Which object is nil?

undefined method `map\' for nil:NilClass

Extracted source         


        
2条回答
  •  误落风尘
    2021-01-19 17:54

    @user_array is nil. Make sure it's set with an array of users to avoid this error message.

    Alternatively, set @user_array to [] (an empty array) if you wish to show no options in the `select, e.g.:

    collection_select @user, :full_name, @user_array || [], :id, 
      { prompt: 'true' }, { class: 'select' }
    

提交回复
热议问题