【问题标题】:Best_in_place gem, does not display text for dropdownsBest_in_place gem,不显示下拉文本
【发布时间】: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,&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 的代码,看看这是否是一个错误,但有人知道我使用它的方式是否有问题吗?

更新

我将 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


    【解决方案1】:

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

    查看更多详情:

    Rails 4 Best in place select collection

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-28
        • 2012-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多