Sweet Marlon! Thanks for the tip.
Duane Johnson
(canadaduane)
On Sep 30, 2005, at 9:11 PM, Marlon Moyer wrote:
> Need to let a user enter a price and don''t want to impose silly
rules
> about what''s valid? Here''s what I''ve figured
out
>
> In your _form.rhtml, replace the standard text_field with this type:
>
> <%= text_field_tag ''listing[price]'',
number_to_delimiter
> (@listing.price) %>
>
> you could also use number_as_currency too if you wanted a dollar sign
> in your field.
>
> next, in your model, add override the default before validation
> method.
>
> def before_validation
> if self.price != nil
>
self.price_before_type_cast.to_s.gsub!(/[^0-9\.\-]/,'''').to_i
> end
> end
>
> This will remove anything that isn''t a number, decimal point, or
> minus sign.
>
>
>
> --
> Marlon
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>