Checkboxes

in the mean time i am using a checkbox like this :

<input type="checkbox" name="var[car]" <%= var.car ?  'checked' : '' 

unless @var == nil %> />

but i am sure there is something better than this in rails like
<%= checkbox_tag ‘var’, ‘car’, :checked => true %>

but this is not working
any help

thanks

nali wrote:

in the mean time i am using a checkbox like this :

<input type=“checkbox” name=“var[car]” <%= var.car ? ‘checked’ : ‘’
unless @var == nil %> />

but i am sure there is something better than this in rails like
<%= checkbox_tag ‘var’, ‘car’, :checked => true %>

but this is not working
any help

thanks

try <%= check_box ‘var’, ‘car’ %>

ben wrote:

nali wrote:

in the mean time i am using a checkbox like this :

<input type=“checkbox” name=“var[car]” <%= var.car ? ‘checked’ : ‘’
unless @var == nil %> />

but i am sure there is something better than this in rails like
<%= checkbox_tag ‘var’, ‘car’, :checked => true %>

but this is not working
any help

thanks

try <%= check_box ‘var’, ‘car’ %>

…thank but aside from that the checkbox to be checked if @var.car
(which is type tinyint1 in mysql) is true and unchecked if false. how do
i make that behaviour? i saw something like :checked => true but it
didn’t really worked. haven’t found anything in wiki either

thanks again

…thank but aside from that the checkbox to be checked if @var.car
(which is type tinyint1 in mysql) is true and unchecked if false. how do
i make that behaviour? i saw something like :checked => true but it
didn’t really worked. haven’t found anything in wiki either

thanks again

If you set the below in your controller, that should do what you
require.

@var.car = 1

yes, but i do not want all the checkboxes to be checked but if there is
someone who sees this information in ‘edit’ - depends when he was
created and if someone set car = 1 - then the checbox will be
automaticly checked (like the html tag # this is a checked box
thanks again

Hi –

On Mon, 3 Jul 2006, nali wrote:

but this is not working
any help

thanks

try <%= check_box ‘var’, ‘car’ %>

…thank but aside from that the checkbox to be checked if @var.car
(which is type tinyint1 in mysql) is true and unchecked if false. how do
i make that behaviour? i saw something like :checked => true but it
didn’t really worked. haven’t found anything in wiki either

Does this do what you need?

<%= check_box_tag “var[car]”, @var.car, 1 %>

David


“To fully realize the potential of Rails, it’s crucial that you take
the time to fully understand Ruby–and with “Ruby for Rails” David
has provided just what you need to help you achieve that goal.”
– DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
See Ruby for Rails!

this work perfect:

<%= check_box “page”, “sent”, :checked => @page.sent %>

thanks for your help!
(sent is tinyint boolean)

nali <nmahatti@…> writes:

but i am sure there is something better than this in rails like
<%= checkbox_tag ‘var’, ‘car’, :checked => true %>

http://rails.outertrack.com/module/ActionView%3A%3AHelpers%3A%3AFormHelper/check_box

Assuming ‘car’ is an integer value, where 0 is unselected and 1 is
selected, the
following should do:

<%= check_box :var, :car %>

If it’s, let’s say, a ‘yes’/‘no’ string, do something like this:

<%= check_box :var, :car, {}, ‘yes’, ‘no’ %>

On Mon, 3 Jul 2006, [email protected] wrote:

then checked status is already automatically determined by calling
@page.sent, which is expected to return 0 (unchecked) or a non-zero
integer (checked). If you change the above to :checked => 0, you’ll
still find that the box is unchecked unless @page.sent returns 0.

s/unchecked/checked/ on last line.

David


“To fully realize the potential of Rails, it’s crucial that you take
the time to fully understand Ruby–and with “Ruby for Rails” David
has provided just what you need to help you achieve that goal.”
– DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
Complete foreword & sample chapters at Ruby for Rails!

Hi –

On Mon, 3 Jul 2006, nali wrote:

this work perfect:

<%= check_box “page”, “sent”, :checked => @page.sent %>

thanks for your help!
(sent is tinyint boolean)

I believe the :checked spec is ignored. If you just do:

<%= check_box “page”, “sent” %>

then checked status is already automatically determined by calling
@page.sent, which is expected to return 0 (unchecked) or a non-zero
integer (checked). If you change the above to :checked => 0, you’ll
still find that the box is unchecked unless @page.sent returns 0.

David


“To fully realize the potential of Rails, it’s crucial that you take
the time to fully understand Ruby–and with “Ruby for Rails” David
has provided just what you need to help you achieve that goal.”
– DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
Complete foreword & sample chapters at Ruby for Rails!