Rails 3.1.3
I have a table 'Contribution' having a column, 'price' which must be
integers.
validate :price => true, :numericality => { :only_intger => true }
then, in creating a new Contribution DB, I need to check the user input
values. Of course, if the values are not valid, it needs to stay in the
same page showing error messages .
in 'contributions_controller.rb',
respond_to do |format|
if @contribution.save
format.html { render action: "new", notice: 'Contribution was
successfully created.' }
format.json { render json: @contribution, status: :created,
location: @contribution }
else
format.html { render action: "index" }
format.json { render json: @contribution.errors, status:
:unprocessable_entity }
end
end
hoping that the 'save' method FAILS upon inputing string values, for
example.
But interestingly, if I input, say, 'this' in the input form, it directs
to the next page and the '0' (an integer, though) value is inserted in
the DB. I do not have any default value to 'price'.
Could anyone point out any mistakes that I am making here?
Thanks in advance.
soichi
--
Posted via
http://www.ruby-forum.com/.