【问题标题】:Rails / Simple form for "selected" option stopped workingRails /“选定”选项的简单表单停止工作
【发布时间】:2017-11-08 18:26:40
【问题描述】:

simple_form 中的selected 选项有问题。

从历史上看,你可以这样做:

f.association :city, label: "City", collection: City.where(country: "France"), label_method: :name, value_method: id, selected: City.first.id    

它突然停止工作,我不知道为什么。无论我尝试什么(City.last.idCity.first.idCity.find_by(name: "Paris")),从现在开始,它都会继续占据我收藏的第一个价值

【问题讨论】:

    标签: ruby-on-rails associations simple-form selected


    【解决方案1】:

    试试这个

     f.association :city, label: "City", collection: City.where(country: "France"),:selected => City.first.id, label_method: :name, value_method: id    
    

    f.association :city, label: "City", collection: City.where(country: "France"),:selected => City.where(country: "France").first.id, label_method: :name, value_method: id
    

    【讨论】:

    • 感谢 Gabbar 的回答,但它不起作用。它一直在挑选我收藏的第一个值
    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 2017-03-25
    • 1970-01-01
    相关资源
    最近更新 更多