how do i get options as well as values from select_tags in my controller

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how do i get options as well as values from select_tags in my controller

fugee ohu
how do i get options as well as values from select_tags in my controller or how do i lookup the options I have states stored in my User model as STATE_TYPES which looks like ["Alabamba", "AL"] ... How do I reference the element in the hash for AL so I can display Alabama in my views instead of AL Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20ba4e7a-ac9d-4839-abd9-c70550f5f89f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how do i get options as well as values from select_tags in my controller

Walter Lee Davis

> On Jun 7, 2018, at 12:48 PM, fugee ohu <[hidden email]> wrote:
>
> how do i get options as well as values from select_tags in my controller or how do i lookup the options I have states stored in my User model as STATE_TYPES which looks like ["Alabamba", "AL"] ... How do I reference the element in the hash for AL so I can display Alabama in my views instead of AL Thanks in advance
>

Browsers only ever send the name of the field and its value. That's the only thing the parameters will ever include. Since you created the select tag, you know what you created it from, and you can reverse out the label from the value. As I have pointed out to you before, you can start with a struct or a nested array and maintain this dictionary of labels and values in such a way that the collection_select helper can build from it, then turn around and use that same data structure to decode the value that the client sends you.

Look back in the list to May 15th, where I suggested you use to_h to make a hash out of your array, and then search it.

Walter


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ACD24092-3968-4F3B-9D9C-A7F93F9DCC6E%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how do i get options as well as values from select_tags in my controller

fugee ohu


On Thursday, June 7, 2018 at 1:46:22 PM UTC-4, Walter Lee Davis wrote:

> On Jun 7, 2018, at 12:48 PM, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Evscyk0lBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> wrote:
>
> how do i get options as well as values from select_tags in my controller or how do i lookup the options I have states stored in my User model as STATE_TYPES which looks like ["Alabamba", "AL"] ... How do I reference the element in the hash for AL so I can display Alabama in my views instead of AL Thanks in advance
>

Browsers only ever send the name of the field and its value. That's the only thing the parameters will ever include. Since you created the select tag, you know what you created it from, and you can reverse out the label from the value. As I have pointed out to you before, you can start with a struct or a nested array and maintain this dictionary of labels and values in such a way that the collection_select helper can build from it, then turn around and use that same data structure to decode the value that the client sends you.

Look back in the list to May 15th, where I suggested you use to_h to make a hash out of your array, and then search it.

Walter



ThanksĀ 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b2383d46-9aeb-406f-83bb-6a234aec9d32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.