[英]Rails 4 best_in_place gem display issues with iterating through list
[英]Best_in_place gem, does not display text for dropdowns
我正在使用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的代碼,以查看這是否是錯誤,但是有人知道我在使用它的方式上是否做錯了什么?
更新資料
我用@user替換了sku.product(只是為了測試模型是否有問題),它在“產品名稱(牛奶)”中顯示正確的選項。
%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模型時,它不會允許我使用產品名稱的下拉列表,因為名稱列是字符串字段而不是數字,因此它無法通過下拉列表將其保存在db中嗎?
嘗試以下解決方案: = best_in_place other_expense, :currency, as: :select, collection: {'RUR' => 'RUR', 'EUR' => 'EUR', 'USD' => 'USD'}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.