hi,
i’m trying to add a select box with the select method, but rails orders
it according to the name, while i needed ordered according to the value,
or just to work in the order i put it in.
this is my array:
@price_range = {"$100-$200" => “0”, “$200-$300” => “1”, “$300-$350” =>
“2”, “$350-$500” => “3”}
and this is my view:
<% fields_for(@description) do |d| -%>
<%= d.select( :price_range, @price_range ) %>
<%end$>
i can’t figure out how to do this, it subtracts one number from the
other number (100 from 200) and then orders from lowest to highest,
which is not what I want.
any help is greatly appreciated,
thanks
On Sep 14, 8:38 pm, Daniel F. [email protected]
wrote:
<%end$>
i can’t figure out how to do this, it subtracts one number from the
other number (100 from 200) and then orders from lowest to highest,
which is not what I want.
any help is greatly appreciated,
thanksPosted viahttp://www.ruby-forum.com/.
That’s no array. It’s a hash, and hashes are unordered - or at the
very least you can never rely on its ordering.
Try this instead:
<%= d.select(:price_range, @price_range.sort) %>
Hope that works.
thanks,
that works great.
is there a way to do this without having to sort? just having them in
the order i placed them?
Erol F. wrote:
On Sep 14, 8:38�pm, Daniel F. [email protected]
wrote:<%end$>
i can’t figure out how to do this, it subtracts one number from the
other number (100 from 200) and then orders from lowest to highest,
which is not what I want.
any help is greatly appreciated,
thanksPosted viahttp://www.ruby-forum.com/.
That’s no array. It’s a hash, and hashes are unordered - or at the
very least you can never rely on its ordering.Try this instead:
<%= d.select(:price_range, @price_range.sort) %>
Hope that works.
On 14 Sep 2008, at 14:10, Daniel F. wrote:
thanks,
that works great.
is there a way to do this without having to sort? just having them in
the order i placed them?
Use an array instead of a hash (which is what sort does - turns the
hash into an array of [key, value] arrays.
Fred
On Sep 14, 9:15 pm, Frederick C. [email protected]
wrote:
On 14 Sep 2008, at 14:10, Daniel F. wrote:
thanks,
that works great.
is there a way to do this without having to sort? just having them in
the order i placed them?Use an array instead of a hash (which is what sort does - turns the
hash into an array of [key, value] arrays.Fred
Which means you’ll need to change your @price_range declaration to an
array of pairs:
@price_range = [ [“$100-$200”, 0], [“$200-$300”, 1], [“$300-$350”, 2],
[“$350-$500”, 3] ]