Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Trouble while loading data in Combobox

#534

I'm having the following problem:

I'm triying to get some data from my database and show it in a combobox in a template, and I created a function in the model class that represents that table to retrieve that data

here is the model class code:

class TipoPago < ActiveRecord::Base

def self.tipos_de_pago

@tipos = find(:all, :order => :display )

@desplegar = []

for tipo in @tipos

#agregar a lo que se mostrara en el select

@desplegar << [ tipo.display , tipo.valor ]

end

@desplegar

end

end

in one view template I have this line:

<%= forma.select :tipo_pago, TipoPago.tipos_de_pago, :prompt => "Seleccione el tipo de pago" %>

forma is an user form

I have tree records in my TipoPagos table:

id | display | valor

----------------------------------

1 | Cheque | chq

2 | Tarjeta de Credito | tc

3 | Orden de compra | oc

The bad think was that when I test It, in my browser the combobox showed:

"Seleccione el tipo de pago"

""

"Orden de compra"

"Tarjeta de Credito"

I didn't understand why it didn't showed "Cheque", the first option in the array

I know it looks like I'm doing something bad somewhere, but the reality was that when I just made a little change to my function, It worked WELL:

class TipoPago < ActiveRecord::Base

def self.tipos_de_pago

@tipos = find(:all, :order => :display )

@desplegar = []

for tipo in @tipos

#

tipo.valor #THIS LINE DOESN'T HAVE ANY SENSE

#

#agregar a lo que se mostrara en el select

@desplegar << [ tipo.display , tipo.valor ]

end

@desplegar

end

end

then, my combobox showed:

"Seleccione el tipo de pago"

"Cheque"

"Orden de compra"

"Tarjeta de Credito"

I took me a little while to get to that change, and for me it doesn't have any sense, that line of code shouldn't be there, but I remove it, It stop working well.

I hope you find a way to fix that if it's a bug o please tell what I'm doing bad

Thank you

Reported by Kenny Davila · July 2nd, 2008 @ 07:35 AM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Pratik
    Pratik
    • State changed from new to wontfix

    Please ask this question in rubyonrails mailing list.

    Thanks.

    July 2nd, 2008 @ 01:31 PM