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 ext开发者_运维问答ract 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??
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
精彩评论