This project is archived and is in readonly mode.
Trouble while loading data in Combobox
Reported by Kenny Davila | July 2nd, 2008 @ 07:35 AM | in 2.x
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
Comments and changes to this ticket
-
Pratik July 2nd, 2008 @ 01:31 PM
- State changed from new to wontfix
Please ask this question in rubyonrails mailing list.
Thanks.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>