我正在使用https://github.com/bernat/best_in_place gem来编辑表单字段
Here is the code I am using:
%tr
%td #{best_in_place sku.product, :name, as: :select, :class=>"best_in_place", collection: Product.all.map { |i| [i.id, i.name]}}
%td #{sku.size}
%td #{sku.kind}
仔细观察,best_in_place方法生成的值似乎缺少"字符串(产品名称)"跨度之间
pry(#<#<Class:0x007fb155848308>>)> best_in_place sku.product, :name, as: :select, :class=>"best_in_place", collection: Product.all.map { |i| [i.id, i.name]}
Product Load (0.4ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT 1 [["id", 4]]
Product Load (0.5ms) SELECT "products".* FROM "products"
=> "<span class=\"best_in_place best_in_place\" data-bip-attribute=\"name\" data-bip-collection=\"[[1,"Milk"],[2,"Water"],[3,"Bread"],[4,"Eggs"],[6,"Yogurt"],[8,"Dogfood"],[5,"Cereal"],[9,"Oatmeal"],[10,"Soda"],[11,"Paper Towels"],[12,"Toilet Paper"],[7,"Coffee Beans"]]\" data-bip-object=\"product\" data-bip-original-content=\"Eggs\" data-bip-skip-blur=\"false\" data-bip-type=\"select\" data-bip-url=\"/products/4\" data-bip-value=\"Eggs\" id=\"best_in_place_product_4_name\">**</span>**"
我正在尝试围绕gem的代码来查看这是否是一个bug,但是有人知道我使用它的方式是否有问题吗?
更新
我用@user替换了sku.product(只是为了测试模型的问题),并且它显示了产品名称(Milk)中的正确选项。
%tr
%td #{best_in_place @user, :phone, as: :select, :class=>"best_in_place", collection: Product.all.map { |i| [i.id, i.name]}}
%td #{sku.size}
%td #{sku.kind}
我想知道在使用Product模型时不会让我使用Product name的下拉列表,因为name列是一个字符串字段而不是数字,所以它不能通过下拉列表保存在db中?
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个解决方案:
= best_in_place other_expense, :currency, as: :select, collection: {'RUR' => 'RUR', 'EUR' => 'EUR', 'USD' => 'USD'}