1
This error happens when the user does not select the option from the select field. The error would even be dealt with if it had not Collect:
NoMethodError in Subdisciplinas#create
Showing _form.html.erb where line #18 raised:
undefined method `collect' for nil:NilClass
<%= f.select :disciplina_id,
options_for_select(
@disciplinas.collect { |disciplina| [disciplina.nome.titleize, disciplina.id] }, @subdisciplina.disciplina_id), {prompt: 'Selecionar disciplina'}, { id: 'disciplinas_select' } %>
</div>
Controller where I believe the error should be dealt with:
def create
@subdisciplina = Subdisciplina.new(subdisciplina_params)
respond_to do |format|
if @subdisciplina.save
format.html { redirect_to @subdisciplina, notice: 'Subdisciplina was successfully created.' }
format.json { render :show, status: :created, location: @subdisciplina }
else
format.html { render :new }
format.json { render json: @subdisciplina.errors, status: :unprocessable_entity }
end
end
end