here is my current code
<%= select_tag(:order, options_for_select(@orders, params[:order].to_s))
%>
I am using some data that is not in a database so I generated a hash
like the following:
@orders = {'Name => ‘name’, ‘Rank’ => ‘rank’, ‘HP’ => ‘hp’, ‘SP’ =>
‘sp’} etc…
it works fine but the problem I have is that the hash is never in the
same order…after reading it looks like i should be using a struct or
an array.
can someone help me convert this hash into an array or suggest the best
way to do this?
it works fine but the problem I have is that the hash is never in the
same order…after reading it looks like i should be using a struct or
an array.
can someone help me convert this hash into an array or suggest the
best
way to do this?
@orders = [[‘Name’, ‘name’], [‘Rank’, ‘rank’], …]
Should do it. Or you might need to swap ‘name’ with ‘Name’. I can
never remember
-philip
@orders = [[‘Name’, ‘name’], [‘Rank’, ‘rank’], …]
Should do it. Or you might need to swap ‘name’ with ‘Name’. I can
never remember
-philip
hmm…i don’t think it likes it.
it’s outputting this:
Namename
Rankrank
etc...
i tried doing this:
<%= select_tag(:order, options_for_select(@orders.collect{|order|
[order[0], order[1]]}, params[:direction].to_s)) %>
but ended up with this output:
Namename
Rankrank
etc...
Do you really need the difference in case? If not, try
@orders = %w(Name Rank SP HP)
I believe that will work…
Roy P. wrote:
Do you really need the difference in case? If not, try
@orders = %w(Name Rank SP HP)
I believe that will work…
Yea, actually that does work fine…i’m trying to order by that field in
the database and i thought it was case sensitive in the SQL query.
however, i do have another sort field
@directions = {‘Ascending’ => ‘ASC’, ‘Descending’ => ‘DESC’}
and ASC and DESC might not be descriptive enough if you have any other
ideas.
thanks for the help so far!
@orders = [[‘Name’, ‘name’], [‘Rank’, ‘rank’], …]
Should do it. Or you might need to swap ‘name’ with ‘Name’. I can
never remember
-philip
hmm…i don’t think it likes it.
Strange. It should. Docs say:
options_for_select([[“Dollar”, “$”], [“Kroner”, “DKK”]])
Dollar\nKroner</
option>
maybe i should just create two more tables : )
Hi Scott!
I am using some data that is not in a database so I generated a hash
like the following:
@orders = {'Name => ‘name’, ‘Rank’ => ‘rank’, ‘HP’ => ‘hp’, ‘SP’ =>
‘sp’} etc…
it works fine but the problem I have is that the hash is never in the
same order…after reading it looks like i should be using a struct or
an array.
AFAIK hashes are not ordered by definition.
I know this may not be very helpful but it may explain why you
experience this behaviour.
Kind regards
Martin