Best_in_place gem,不显示下拉列表的文本

时间:2015-11-18 22:15:45

标签: javascript ruby-on-rails ruby-on-rails-4.1 best-in-place

我正在使用https://github.com/bernat/best_in_place gem来编辑表单字段

似乎当前值显示为' - '使用集合时。 enter image description here

但是,点击下拉列表会显示当前值: enter image description here

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,&quot;Milk&quot;],[2,&quot;Water&quot;],[3,&quot;Bread&quot;],[4,&quot;Eggs&quot;],[6,&quot;Yogurt&quot;],[8,&quot;Dogfood&quot;],[5,&quot;Cereal&quot;],[9,&quot;Oatmeal&quot;],[10,&quot;Soda&quot;],[11,&quot;Paper Towels&quot;],[12,&quot;Toilet Paper&quot;],[7,&quot;Coffee Beans&quot;]]\" 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中?

2 个答案:

答案 0 :(得分:0)

创建键和值相同的选项哈希值。

检查以获取更多详细信息:

Rails 4 Best in place select collection

答案 1 :(得分:0)

试试这个解决方案: = best_in_place other_expense, :currency, as: :select, collection: {'RUR' => 'RUR', 'EUR' => 'EUR', 'USD' => 'USD'}

相关问题