views:

39

answers:

2

Hello,

I am trying to re render a page with a checkbox that has been selected prior to the render.

With the result, I converted it to an integer.

if I have the following code, how do I make the checkbox either checked or not

check_box("price", "total", {:checked => @checkVal})  where @checkVal is my checked/not value (int)
+2  A: 

If you are using check_box, Rails is assuming that you have a @price object that has a total attribute. If this is the case, you can set the checkbox to be checked by setting @price.total to true (likely in your controller). Example:

class UserController < ApplicationController

  def new
    @user = User.new
    @user.terms_of_service = true
  end

will result in a checked box in your view:

<%= check_box(:user, :terms_of_service) %>

If you don't have a Price model with a total attribute, you likely should be using check_box_tag instead (which has info on how to set checked).

Lytol
+1  A: 

If the data isn't coming from a table you want to be using check_box_tag:

check_box_tag("price", "total", @checkVal)
Mike Sutton