# Newbie problem

**URL:** <https://www.ruby-forum.com/t/newbie-problem/194153>\
**Category:** Rails\
**Created:** [August 31, 2010, 9:30am UTC](https://www.ruby-forum.com/t/newbie-problem/194153 "2010-08-31T09:30:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 9:30am UTC](https://www.ruby-forum.com/t/newbie-problem/194153/1 "2010-08-31T09:30:42Z")

</div>

Trying to learn how to work with arrays. Using RubyMine.  
Trouble with array syntax below in html.erb file.

 Ruby Arrays \<%= array = ['a','b','c'] %\>

Shows up in browser as this:  
[“a”, “b”, “c”]

using 1.9.1  
Thanks for any suggestions.

–  
Warm Regards,  
Todd W.  
removed\_email\_address@domain.invalid  
801.814.9084

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 9:50am UTC](https://www.ruby-forum.com/t/newbie-problem/194153/2 "2010-08-31T09:50:02Z")

</div>

On 31 August 2010 08:29, Todd W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= array = [‘a’,‘b’,‘c’] %\>  
> Shows up in browser as this:  
> [“a”, “b”, “c”]

What’s wrong with that?

> Thanks for any suggestions.

Your post doesn’t include any questions, so it’s a little hard to know  
where you want help.

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 10:57am UTC](https://www.ruby-forum.com/t/newbie-problem/194153/3 "2010-08-31T10:57:21Z")

</div>

On 31 August 2010 08:29, Todd W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Shows up in browser as this:  
> [“a”, “b”, “c”]

You have asked it to show the array and it has done so. What are you  
trying to do? Possibly you need something to use something like  
array.each. Possibly have a look at some basic Ruby tutorials (as  
opposed to Rails tutorials).

> using 1.9.1

I presume that is the version of Ruby, I don’t know which version of  
Rails you are using, but I believe there are problems with ruby 1.9.1  
and some versions of rails.

Colin

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/newbie-problem/194153/4 "2010-08-31T21:38:28Z")

</div>

On 31 August 2010 20:24, Todd W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Im not getting the output I expect. In the tutorial I am doing. It is  
> suppose to just write the values to the browser.  
> Which would write a,b,c to the browser and shouldn’t also be showing the  
> array brackets or double quotes.  
> Then I would be able to continue to call the values of the array and write  
> the results to a browser using ruby code within the erb file.  
> My question: Whats wrong with the code I’m writing?

There’s nothing wrong with your code, it’s working perfectly. But if  
you want to iterate the array, there are several ways.  
Most commonly, you can use “.each”:

\<% array = [‘a’,‘b’,‘c’] %\>  
\<% array.each do |element| %\>  
\<%= element %\>  
\<% end %\>

but if the format you’ve noted is specific (“a,b,c”) then you can use  
the “.join” method:

\<% array = [‘a’,‘b’,‘c’] %\>  
\<%= array.join(", ") %\>

I would recommend having a play with the Enumerable and Array API pages:  
[http://ruby-doc.org/core/classes/Enumerable.html](http://ruby-doc.org/core/classes/Enumerable.html)  
[http://ruby-doc.org/core/classes/Array.html](http://ruby-doc.org/core/classes/Array.html)

Rails add more functionality to these, but getting a grasp on the Ruby  
will help.

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 9:25pm UTC](https://www.ruby-forum.com/t/newbie-problem/194153/5 "2010-08-31T21:25:35Z")

</div>

Im not getting the output I expect. In the tutorial I am doing. It is  
suppose to just write the values to the browser.

Which would write \*a,b,c \*to the browser and shouldn’t also be showing  
the  
array brackets or double quotes.  
Then I would be able to continue to call the values of the array and  
write  
the results to a browser using ruby code within the erb file.  
My question: Whats wrong with the code I’m writing?  
Thanks for your feedback!

On Tue, Aug 31, 2010 at 1:48 AM, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> where you want help.

–  
Warm Regards,  
Todd W.  
removed\_email\_address@domain.invalid  
801.814.9084

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 9:46pm UTC](https://www.ruby-forum.com/t/newbie-problem/194153/6 "2010-08-31T21:46:05Z")

</div>

On 31 August 2010 20:40, Greg D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Tue, Aug 31, 2010 at 2:37 PM, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > \<% array = [‘a’,‘b’,‘c’] %\>
> 
> %w( a b c )

I wasn’t going to get into array-making idioms - I just stuck to the  
OP’s method of populating his array 🙂

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 10:04pm UTC](https://www.ruby-forum.com/t/newbie-problem/194153/7 "2010-08-31T22:04:14Z")

</div>

Thank you much. I get it now!

On Tue, Aug 31, 2010 at 1:37 PM, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> There’s nothing wrong with your code, it’s working perfectly. But if

–  
Warm Regards,  
Todd W.  
removed\_email\_address@domain.invalid  
801.814.9084

---

<div class="post-metadata">

**Author:** ![twerth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/aca169/32.png) [@twerth](https://www.ruby-forum.com/u/twerth)\
**Post date:** [August 31, 2010, 9:44pm UTC](https://www.ruby-forum.com/t/newbie-problem/194153/8 "2010-08-31T21:44:20Z")

</div>

On Tue, Aug 31, 2010 at 2:37 PM, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> \<% array = [‘a’,‘b’,‘c’] %\>

%w( a b c )

–  
Greg D.  
[destiney.com](http://destiney.com) | [gregdonald.com](http://gregdonald.com)
