9

I am using the best_in_place gem in a project, and i am trying to display a checkbox on it's own place, but i cannot do it. I am searching about it, but i cannot find out the answer anywhere. I just can find people talking about display either "no" or "yes"... Or anything else. But i just want to see the checkbox checked or not.

Norto23
  • 2,249
  • 3
  • 23
  • 40
Victor Augusto
  • 2,406
  • 24
  • 20

4 Answers4

10

I am using font-awesome but you can use it also with bootstrap or other images. My solution for displaying checkboxes were simply using the raw method to render a checkbox image (in my case one of the font-awesome icons)

= best_in_place @project, 
    :active, 
    :type => :checkbox, 
    :collection => {false: raw("<i class='icon-check-empty'></i>"), true: raw("<i class='icon-check'></i>")}

And now it looks like the following:

best_in_place with checkboxes

anka
  • 3,817
  • 1
  • 30
  • 36
3

I've managed to make a hack-around using unicode characters ☐ and ☑

<span style='font-size: 1.75em;'>
<%= best_in_place a,
:bool, 
:type => :checkbox,
:collection => ["&#x2610;", "&#x2611;"]%>
</span>

The <span> wrapper helps with choosing the size in this case. This is a short term solution and a checkbox with an AJAX call would definitely be better I guess...

Sash
  • 4,448
  • 1
  • 17
  • 31
  • @megas, try encapsulating @Sash's collection with raw: `:collection => [raw("☐"), raw("☑")]` – Tass Jun 07 '13 at 17:32
1

I've forked the original best_in_place gem and modified it with support for displaying an actual, standard HTML checkbox. My fork can be found here: https://github.com/jdashton/best_in_place

In case you're unfamiliar with using gems directly from github, the following line in your Gemfile should do the trick:

gem 'best_in_place', github: 'jdashton/best_in_place'
Daniel Ashton
  • 1,388
  • 11
  • 23
-1

It's not supported in the current version. However, it's pretty easy to do. Create a checkbox where you need it, and fire an ajax call to the server with some javascript.

Check out this stackoverflow answer for an example.

Community
  • 1
  • 1
IAmNaN
  • 10,305
  • 3
  • 53
  • 51