Pregunta

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?

¿Fue útil?

Solución 2

I figured out this solution in case anyone is wondering. I would still be open to a less hack-ish way to achieve this.

add an "active" class to your field

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

In your js:

$(".editable").editable();
$(".active").html("");

Otros consejos

Try this:

= editable person, :active, classes: {"Yes" => "glyphicon-ok", "No" => "glyphicon-remove"}, class: "glyphicon"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top