trickydiddy
trickydiddy

Reputation: 587

How to set a checkbox in Rails only as a visual representation of the data (Read Only)?

I have a boolean value on a task model I want to show the value in a checkbox without the possiblity of changing the checkbox value.

How can I achieve this? Why doesn't my code work?

<%= form_for(@task) do |f| %>
 <%= f.check_box :important, {}, disabled="disabled" %>
<% end %>

Thanks in advance.

Upvotes: 0

Views: 790

Answers (2)

trickydiddy
trickydiddy

Reputation: 587

I finally found an easy solution. The check_box_tag or check_box just confused me and I could not call the boolean value related on the checkbox (checked = true, unckecked = false).

This works perfectly:

<%= form_for(@task) do |f| %>
 <%= f.check_box :important, :disabled => true %>
<% end %>

Upvotes: 1

bryce
bryce

Reputation: 3051

use check_box_tag with disabled: true.

Upvotes: 2

Related Questions