I am using .keys on a hash to create an array that is than displayed
in a view with .each - why does it not display the keys in the order
added to the hash?
I would like to controll how the array is displayed - I want the
checkboxes to display like I added them to the hash, but it doesn't -
I can't figure out how it is displayed, when I change the order of the
hash it does little to the view.
I am using .keys on a hash to create an array that is than displayed
in a view with .each - why does it not display the keys in the order
added to the hash?
I would like to controll how the array is displayed - I want the
checkboxes to display like I added them to the hash, but it doesn't -
I can't figure out how it is displayed, when I change the order of the
hash it does little to the view.
#action for view
def list_modules
@mods = @user.modules@list = mod_types.keys # here I am making an array out of the hash
if request.post?
redirect_to :action => "manage_modules"
end
end
View
-----------
...
<%@list.each do |mod|%>
<%= check_box_tag("mods", mod ,false, {:class =>
"class"}) %>
<%= mod%><br />
<%end%>
Hashes are unordered data structures. You can't get them in order inserted with a normal hash. You will have to use an array or google for an ordered hash class for ruby.
I don't want to sort the hash - I want to determine the order the
values from the hash are displayed. I can't use an array because of
what I need to be able to do after users select values.
The view uses the keys form the hash - is there any way that I can
controll the order they are displayed?
i would imagine it wouldn't take much to modify whatever it is you are
doing with users, but since you didn't provide any details on that, I
can't provide any possible solutions.
I don't want to sort the hash - I want to determine the order the
values from the hash are displayed. I can't use an array because of
what I need to be able to do after users select values.
The view uses the keys form the hash - is there any way that I can
controll the order they are displayed?