
February 23rd, 2008, 04:24 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
You're not going to get that method called when the value is not set in the checkbox. That's because the HTTP protocol will not send the field value if the checkbox is not set. The solution is to
1. Set the underlying model's default value to 0 for the field, so when you create a new instance, the default is set.
2. Check if model.within is set after you've set the other values and then set it yourself, if it isn't:
Code:
model = Model.new(params[:model])
if model.within.nil?
model.within = 0
end
model.save
3. Override the new method for your model and make it set the value of model.within first before updating with all the passed in params.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|