问题
I have a range field that, when slid right, needs to make the output "more negative" up to -100.
Here's my current code:
<%= f.range_field :Question1, :in => 0..-100, :step => '.1' %>
Obviously, using :in => -100..0 works fine, but when I switch it to 0..-100, sliding to the right goes up to 100, which is clearly wrong. I need the user to be able to slide right in order to get a more negative number. Does anyone know how to make this happen?
If this is not possible, is there a way to set up :in => 0..100 but then make the number negative before it's put into the database?
回答1:
I believe you could use a before_save
filter to negate the value before saving it, or a before_validation
to negate it before it validates and then you could validate that the number you are getting is what you want.
来源:https://stackoverflow.com/questions/15313892/rails-range-field-from-0-to-100