Hello all.
I''m trying to use a checkbox but can''t seem to use in the
right way.
All I want is to show a checkbox that is checked or not depending on a
is_normal variable (this is a controller variable that isn''t saved in
the database), but it doesn''t work because the checkbox is always
checked even if is_normal is false. Here is the code:
<%= check_box_tag(''is_normal'', true, "checked"
=> is_normal) %>
and the resulted html:
<input checked="checked" id="is_normal"
name="is_normal"
type="checkbox" value="true" />
To overcome this used the following code, but this is only a
workaround to the problem.
<% if(is_normal) %>
<%= check_box_tag(''is_normal'', true,
"checked" => true) %>
<% else %>
<%= check_box_tag(''is_normal'', true) %>
<% end %>
Is there a way to do this in a better way?
I''m using Rails 0.13.1
Thanks for your help.
Best regards,
Hugo
Hello all.
I''m trying to use a checkbox but can''t seem to use in the
right way.
All I want is to show a checkbox that is checked or not depending on a
is_normal variable (this is a controller variable that isn''t saved in
the database), but it doesn''t work because the checkbox is always
checked even if is_normal is false. Here is the code:
<%= check_box_tag(''is_normal'', true, "checked"
=> is_normal) %>
and the resulted html:
<input checked="checked" id="is_normal"
name="is_normal"
type="checkbox" value="true" />
To overcome this used the following code, but this is only a
workaround to the problem.
<% if(is_normal) %>
<%= check_box_tag(''is_normal'', true,
"checked" => true) %>
<% else %>
<%= check_box_tag(''is_normal'', true) %>
<% end %>
Is there a way to do this in a better way?
I''m using Rails 0.13.1
Thanks for your help.
Best regards,
Hugo