Displaying 'ticked' check boxes

I need to display check boxes as ‘ticked’ in my edit function where
there is a corresponding value for them in the database.

In my new function a user can select between 1 and 4 tick boxes and I
need these ticked check boxes displayed back to them when they go in to
the edit function for that database item.

Most appreciated if anyone out there can help please?

Here’s the code from the new function that sets up the database fields
from the check boxes - so I just need to display these as ‘ticked’ in my
edit function.

tr>

Agreement Type &nbsp Contract &nbsp &nbsp Data Transfer Agreement &nbsp &nbsp Data Destruction Agreement&nbsp &nbsp Non-Disclosure Agreement&nbsp &nbsp

Currently my edit function is as below but I’m missing the bit to get
the boxes ticked.

Agreement Type &nbsp Contract &nbsp &nbsp Data Transfer Agreement &nbsp &nbsp "">Data Destruction Agreement&nbsp &nbsp "">Non-Disclosure Agreement&nbsp &nbsp

2009/4/7 Helen S. [email protected]

Here’s the code from the new function that sets up the database fields

--

Hi Helen,
Had a bit of trouble reading the last section.
To check a checkbox, you have to say:
<input type=“checkbox” … checked=“checked” />
The “value” attribute can be whatever you set it, but maybe use the
rails
default which is 0 and 1 for not-ticked and ticked respectively. Bear
in
mind that the html spec says that if you don’t tick the box, it won’t
get
sent back to the server so other things being equal, your server won’t
get
to see 0.

You should read
ActionView::Helpers::FormHelper as
a
starting point for what rails can do to help you build forms and in
particular check out the ‘check_box’ function which employs a little
hack to
get round the html spec so that you do see ‘0’.

Ideally, you want something a little like this:
<% form_for :transfer do |f| %>

<%= f.checkbox ‘agreement_1’ %>

<% end %>
I’m assuming you have a @transfer model or object which is created in
your
controller action with an ‘agreement_1’ method that returns a boolean or
something like that.

You can of course create the checkbox manually, but you’ll need to write
code to test the boolean and insert the checked attribute/value pair
into
your tag:
<%
checked=""i
checked = %{checked=“checked”} if agreement_1
%>
<input … <%=checked%> />


Daniel B.

http://blog.web17.com.au