different between these two array method.

17 views
Skip to first unread message

phoe san

unread,
Jul 2, 2012, 4:59:57 AM7/2/12
to rubyonra...@googlegroups.com
Dear friends,

What is different between these two array method.

First Array Method

arr = ps_array["1"]
arr += ps_array["2"]
arr += ps_array["3"]


Second Array Method

arr = [ps_array["1"],ps_array["2"],ps_array["3"]]


yours,

phoesan

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Jul 2, 2012, 5:07:22 AM7/2/12
to rubyonra...@googlegroups.com
On 2 July 2012 09:59, phoe san <li...@ruby-forum.com> wrote:
> Dear friends,
>
> What is different between these two array method.
>
> First Array Method
>
> arr = ps_array["1"]

What is the type of ps_array["1"]

Colin

> arr += ps_array["2"]
> arr += ps_array["3"]
>
>
> Second Array Method
>
> arr = [ps_array["1"],ps_array["2"],ps_array["3"]]
>
>
> yours,
>
> phoesan
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
>

phoe san

unread,
Jul 2, 2012, 5:26:38 AM7/2/12
to rubyonra...@googlegroups.com
<%= collection_select(:sport_name,count,Sport.find( :all, :order => 'id'
),
:id, :sport_name, {:selected =>@sport_id})%>

Collection_select Value.
We take data from collection_select by params[:sport_name]

In Controller, we use this
ps_array = params[:sport_name]
we get the data

First array method , It doesn't work.
Second Method , It Work.

Regards,

thil

unread,
Jul 2, 2012, 5:32:59 AM7/2/12
to rubyonra...@googlegroups.com
Hi,

+ operator won't works in array I think but used as concatenation in staring.

Second scenario of your case works fine.

Thanks,
senthil

Colin Law

unread,
Jul 2, 2012, 5:37:54 AM7/2/12
to rubyonra...@googlegroups.com
On 2 July 2012 10:26, phoe san <li...@ruby-forum.com> wrote:
> <%= collection_select(:sport_name,count,Sport.find( :all, :order => 'id'
> ),
> :id, :sport_name, {:selected =>@sport_id})%>
>
> Collection_select Value.
> We take data from collection_select by params[:sport_name]
>
> In Controller, we use this
> ps_array = params[:sport_name]
> we get the data
>
> First array method , It doesn't work.
> Second Method , It Work.

Please remember to quote the previous message, remember this is a
mailing list not a forum (though you may be accessing it via a forum
interface). Now we will have to look back at the previous message to
see your methods.

When you say
arr = ps_array["1"]
arr is probably a string not an array, so then when you use
arr += ps_array["2"]
it will concatenate the second string onto the first.

Have a look at the Rails Guide on debugging for ideas on how to debug
your code so that you can work out what is going on when you have this
sort of problem.

Colin

phoe san

unread,
Jul 2, 2012, 5:48:54 AM7/2/12
to rubyonra...@googlegroups.com
Hi Sentil and Colin,

ႊThank for your reply message and solution!
Reply all
Reply to author
Forward
0 new messages