# Listing?

**URL:** <https://www.ruby-forum.com/t/listing/130436>\
**Category:** Rails\
**Created:** [February 28, 2008, 6:54am UTC](https://www.ruby-forum.com/t/listing/130436 "2008-02-28T06:54:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 28, 2008, 6:54am UTC](https://www.ruby-forum.com/t/listing/130436/1 "2008-02-28T06:54:38Z")

</div>

Hi RoR Developers

I got tiny problem here. Actually I asked before but there was not any  
answer and asking again.

I have template.yml file.]  
get\_config=YAML.load(File.open("…/template.yml"))  
$temp1path=get\_config[“template”][“templatename1”]

I can get the values by using matrix one by one like above but how can I  
list only right side I mean this is my template.yml file

template:  
templatename1: template\_of\_roster.xml  
templatename2: template\_of\_roster1.xml  
templatename3: template\_of\_roster2.xml  
templatename4: template\_of\_roster3.xml

only this column.  
template\_of\_roster.xml  
template\_of\_roster1.xml  
template\_of\_roster2.xml  
template\_of\_roster3.xml

thank you for any help or commend.

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 28, 2008, 7:44am UTC](https://www.ruby-forum.com/t/listing/130436/2 "2008-02-28T07:44:27Z")

</div>

On Feb 28, 2008, at 12:54 AM, Ibrahim D. wrote:

> can I  
> template\_of\_roster.xml  
> template\_of\_roster1.xml  
> template\_of\_roster2.xml  
> template\_of\_roster3.xml
> 
> thank you for any help or commend.

You’ll probably find that get\_config.class == Hash  
so you can get the values with:  
get\_config[“template”].values  
which gives you an Array over which you could iterate with .each

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 28, 2008, 8:33am UTC](https://www.ruby-forum.com/t/listing/130436/3 "2008-02-28T08:33:44Z")

</div>

Rob B. wrote:  
On Feb 28, 2008, at 12:54 AM, Ibrahim D. wrote:  
can I  
template\_of\_roster.xml  
template\_of\_roster1.xml  
template\_of\_roster2.xml  
template\_of\_roster3.xml

thank you for any help or commend.

You’ll probably find that get\_config.class == Hash  
so you can get the values with:  
get\_config[“template”].values  
which gives you an Array over which you could iterate with .each

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

I wrote something like this  
require ‘yaml’  
get\_config=YAML.load(File.open(“C:/yotta/config/template.yml”))  
get\_config.class == Hash  
get\_config[“template”].values  
get\_config.each do |k,v|  
puts v.inspect  
end

result  
{“templatename1”=\>“template\_of\_roster.xml”,  
“templatename2”=\>“template\_of\_roster1.xml”,  
“templatename3”=\>“template\_of\_roster2.xml”, “templatename4”=  
“template\_of\_roster3.xml”}

why I can not get only second column. I only want this side.  
template\_of\_roster.xml  
template\_of\_roster1.xml  
template\_of\_roster2.xml  
template\_of\_roster3.xml

how should I change my codes.  
thank you very much for your help Rob B. …

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 28, 2008, 8:40am UTC](https://www.ruby-forum.com/t/listing/130436/4 "2008-02-28T08:40:48Z")

</div>

On Feb 28, 2008, at 2:33 AM, Ibrahim D. wrote:

> I wrote something like this  
> require ‘yaml’  
> get\_config=YAML.load(File.open(“C:/yotta/config/template.yml”))

This is a boolean expression, it doesn’t _do_ anything to the  
get\_config object

> get\_config.class == Hash

You should save this in a variable

> get\_config[“template”].values  
> get\_config.each do |k,v|  
> puts v.inspect  
> end

or just do:  
puts get\_config[“template”].values

> template\_of\_roster2.xml  
> template\_of\_roster3.xml
> 
> how should I change my codes.  
> thank you very much for your help Rob B. …

You’re really not having issues with Rails, but with plain old Ruby  
(and YAML from the standard library, of course).

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 28, 2008, 8:55am UTC](https://www.ruby-forum.com/t/listing/130436/5 "2008-02-28T08:55:37Z")

</div>

hmm  
how can I convert to string I mean I know to\_s but how will I use it  
here. I want to assign the values to variable.  
I have selection which is taken these values.

\<%  
templateOptions = “”  
@templates.each do |i|  
templateOptions = templateOptions + “#{i}”  
end  
%\>  
\<%=select\_tag “templates”, templateOptions %\>

thank you very much again…

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 28, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/listing/130436/6 "2008-02-28T14:18:28Z")

</div>

On Feb 28, 2008, at 2:55 AM, Ibrahim D. wrote:

> ```
> end
> %>
> <%=select_tag "templates", templateOptions %>
> 
> ```
> 
> thank you very much again…

> **[ActionView::Helpers::FormOptionsHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000944)**
>
> Provides a number of methods for turning different kinds of containers into a set of option tags.

\<%= select\_tag “templates”,  
options\_for\_select(get\_config[“template”].values) %\>

Even if you were to build it yourself, you might find Enumerable#map  
(aka, Enumerable#collect) and Array#join useful:

templateOptions = @templates.map {|t| %{#{t}\</  
option\>} }.join

These particular strings aren’t likely to pose a problem, but you  
should also know about ERB::Util#html\_escape (often seen in views as  
just h)  
[http://api.rubyonrails.org/classes/ERB/Util.html#M000148](http://api.rubyonrails.org/classes/ERB/Util.html#M000148)

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 29, 2008, 1:08am UTC](https://www.ruby-forum.com/t/listing/130436/7 "2008-02-29T01:08:03Z")

</div>

> -Rob
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid  
> thank you very much.
