0

I have an array that is returned from a model that does not correspond to the view/controller. (i.e Data is from Foo, while I'm in '/bar/'). Therefore I cannot access them via the conventional

params[:someItem]

So I am trying to extract values like this

someVariable = @array[0]

However I get a scrambled mess:

#<Promotion:0x3b74140>

Seeing as that the value I want is an int, I tried calling .to_i, which threw a No Such Method error. Calling to_int gave the same result.

Question: How do I get this value out of the array? And as an aside, why do .to_i and .to_int not work??

1 Answer 1

3

As per my understanding, You are trying to access Array of model objects. When you write

someVariable = @array[0]

then it will give you the first model object from @array. If you want to access object values then you can use like this

modelObj = @array[0]
someVariable = modelObj.my_attribue_name
Sign up to request clarification or add additional context in comments.

1 Comment

Ahh! Its an array of OBJECTS! Thanks, I thought it was an int array. That solves it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.