0

I'm using the x-editable-rails gem with bootstrap to display an inline-editable field for my model. This particular field is a boolean field called "active".

I have this in my rails view (slim) to display the model:

table.table
  thead
    tr
      th Name
      th Active
  tbody
    - @person.each do |person|
      tr
        td = person.name
        td = editable person, :active

This works perfectly fine and generates entries with the name, and a true/false for the active field.

But "true/false" is a bit of an inelegant way to display a boolean field, so I would like to change this to glyphicon-ok / glyphicon-remove. I can get the icon to display by just specifying the class as follows:

td = editable person, :active, 
              class: "glyphicon glyphicon-#{person.active ? 'ok' : 'remove'}"

However, this still leaves the "true/false" text. How do I prevent it from displaying that?

4

2 回答 2

0

尝试这个:

= editable person, :active, classes: {"Yes" => "glyphicon-ok", "No" => "glyphicon-remove"}, class: "glyphicon"
于 2014-01-21T06:31:30.470 回答
0

我想出了这个解决方案,以防有人想知道。我仍然愿意以一种不那么骇人听闻的方式来实现这一目标。

在您的字段中添加一个“活动”类

td = editable person, :active, 
              class: "active glyphicon glyphicon-#{person.active ? 'ok' : 'remove'}"

在你的 js 中:

$(".editable").editable();
$(".active").html("");
于 2014-01-22T20:40:45.917 回答