在我看来,我有一个collection_select。我希望它提示用户选择会话变量是否设置为0.其他工作正常但如果条件为0则告诉我没有方法' id'。
- if session[:ptype_id] == 0
= collection_select :ptype, :id, Ptype.all.order(:part_type), :id, :part_type, {:prompt => "Select Type"}, :onchange => "ptype_set(value)"
- else
= collection_select :ptype, :id, Ptype.all.order(:part_type), :id, :part_type, {:selected => session[:ptype_id]}, :onchange => "ptype_set(value)"
错误......
undefined method `id' for #<Ptype::ActiveRecord_Relation:0x007f9bcf138428>