【发布时间】:2015-11-18 22:15:45
【问题描述】:
我正在使用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 的代码,看看这是否是一个错误,但有人知道我使用它的方式是否有问题吗?
更新
我将 sku.product 替换为 @user(只是为了测试模型是否存在问题),它会显示产品名称(牛奶)中的正确选项。
%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}
我想知道在使用产品模型时它不会让我使用产品名称的下拉列表,因为名称列是字符串字段而不是数字,因此无法通过下拉列表将其保存在数据库中?
【问题讨论】:
标签: javascript ruby-on-rails ruby-on-rails-4.1 best-in-place