代码之家  ›  专栏  ›  技术社区  ›  fiskeben

无法将所选集合保存到对象

  •  0
  • fiskeben  · 技术社区  · 15 年前

    我快疯了。

    class Course
       belongs_to :commune
    end
    

    class Commune
       has_many :courses
    end
    

    在课程的新视图中,我有一个下拉列表,用户在其中选择commune:

    f.collection_select(:commune, get_commune_list, :id, :commune, { :prompt => true })
    

    (get\u commune\u list是一个helper方法,它返回commune对象的列表)

    但当我试图保存它时,我要么得到以下错误:

    需要Commune(#2176182100),获取字符串(#2148246520)

    参数如下所示:

    {"course"=>{"price"=>"6000",
     "title"=>"Some title",
     "commune"=>"10",
     ...
    }
    

    1 回复  |  直到 15 年前
        1
  •  0
  •   AMIT    15 年前

    不是吗?

    f.collection_select (:commune, :commune_id, get_commune_list, :id, :commune, { :prompt => true })