# Here's a quick test I made to demonstrate:
# Template:
Update me: <%= check_box_tag 'update_me' %>
<%= observe_field 'update_me', :url => { :action => "update_checkbox" }, :with => 'checked' %>
# This makes a field with an id of "update_me" and creates the observer
# that will be called when it's checked
# The :with option means our parameter will be called "checked"
# Clicking the box shows this in the log:
Parameters: {"checked"=>"1", ....
Parameters: {"checked"=>"null", ....
# So, our box will either be null or 1 (they're both strings, though!)
# Here's the controller code to make sure things are working:
def update_checkbox
@checked = '1' == params[:checked]
render :update do |page|
page.alert "Checked value: #{@checked}"
end
end
|