Forum: Rails-ES depornto ya no pudo mas ActionView::TemplateError (can't convert Fixnum into String)

Posted by Angel Mauricio Pino Gonzalez (Guest)
on 2009-07-01 09:28
(Received via mailing list)
Tengo un helper que crea mis index
y de la nada dejo de funcionar, deshice los ultimos cambios pero aun
asi no se arreglo.
Alguna idea?

el
index.html.rb que llama al helper es:

<%=
cps = ["folio","contrato.folio","contratocomercio.codigo_comercio",
"nomina.folio",
                  "fecha", "trxs","monto", "md_pct", "md_pct_emisor",
"md_pct_operadora",
                  "md_pesos", "md_pesos_emisor", "md_pesos_operadora",
                  "valor_trx", "total_valor_trx"]

sz =  [8, 4, 5, 17, 12, 7, 12, 6, 6, 6, 10, 10, 10,5,10]

if (@txtsql["nomina.folio"].blank? ||(! 
@txtsql["contrato.folio"].blank?) ||
        (! @txtsql["contratocomercio.codigo_comercio"].blank?) ||
        (! @txtsql["fecha"].blank?) || (! @txtsql["trxs"].blank?) ||
        (! @txtsql["monto"].blank?) ||(@contdepositos.size == 0))

  listado(@contdepositos,
        {:cps => cps,
        :size => sz,
        :ttl => t(:contdeposito, :count => @contdepositos.size),
        :cls => Contdeposito})
else
  listado(@contdepositos,
        {:cps => cps,
        :size => sz,
        :ttl => t(:contdeposito, :count => @contdepositos.size),
        :cls => Contdeposito,
        :enc_link_esp => link_to( image_tag('delete.png'),
"contdepositos/" + @txtsql["nomina.folio"],
                                   :confirm => '¿ Esta ud seguro ?',
:method => :delete,
                                   :title => "Eliminar
contabilizacion(2) de una nomina completa")
        })

end
%>

mi helper es el siguiente:

laparte que dejo de funcionar:

# Methods added to this helper will be available to all templates in
the application.
module ApplicationHelper

  def listado( registros, otro )
    campos = otro[:cps]
    sizes = otro[:size]
    clase = otro[:cls]
    edit_path = otro[:edit_path].nil? ? "" : otro[:edit_path]
    new_title = otro[:new_title].nil? ? "Crear un registro" : 
otro[:new_title]
    edit_title = otro[:edit_title].nil? ? "Modifica este registro." :
otro[:edit_title]
    if otro[:delete_path]
      delete_title = otro[:delete_title]
      delete_path  = otro[:delete_path]
    end
    ad = []
    if otro[:adicional_mono]
      ad << {:mono   => otro[:adicional_mono],
             :titulo => otro[:adicional_titulo],
             :path   => otro[:adicional_path]}
    elsif otro[:adicional]
      if otro[:adicional].is_a?(Array)
        ad += otro[:adicional]
      elsif otro[:adicional].is_a?(Hash)
        ad << otro[:adicional]
      end
    end
    # encabezados especiales
    enc_ad1_path   = otro[:enc_ad1_path]
    enc_ad1_titulo = otro[:enc_ad1_titulo]
    enc_ad1_mono  = otro[:enc_ad1_mono]
    enc_ad2_path   = otro[:enc_ad2_path]
    enc_ad2_titulo = otro[:enc_ad2_titulo]
    enc_ad2_mono  = otro[:enc_ad2_mono]
    enc_ad3_path   = otro[:enc_ad3_path]
    enc_ad3_titulo = otro[:enc_ad3_titulo]
    enc_ad3_mono  = otro[:enc_ad3_mono]
    color_txt_fld = otro[:color]
    # Fin encabezados especiales
    s = %Q!<table
class="detalle">\n<caption>#{otro[:ttl]}</caption>\n<tr
class="titulos">!
    # Titulos
    campos.each {|cp| s += %Q!\n<td>#{
clase.human_attribute_name(cp).gsub(/\./,"<br>")}</td>!  }
    s += "<td>"
    s += %Q!#{ link_to image_tag('add.png'), otro[:new_path], :title
=> new_title }! if otro[:new_path]
    s += %Q!#{ link_to image_tag(enc_ad1_mono), enc_ad1_path, :title
=> enc_ad1_titulo}! if enc_ad1_path
    s += %Q!#{ link_to image_tag(enc_ad2_mono), enc_ad2_path, :title
=> enc_ad2_titulo}! if enc_ad2_path
    s += %Q!#{ link_to image_tag(enc_ad3_mono), enc_ad3_path, :title
=> enc_ad3_titulo}! if enc_ad3_path
    s += otro[:enc_link_esp] if otro[:enc_link_esp]
    s += %Q!</td></tr>\n!

    otro[:save_path] = clase.name.pluralize.downcase if 
otro[:save_path].nil?
    otro[:save_path] = otro[:save_path][1..-1]       if
otro[:save_path][0,1] =="/"

    s += %Q!<form action="/#{otro[:save_path]}" method="get">!
    s += %Q!<input name="authenticity_token" type="hidden"
value="#{form_authenticity_token}" />!
    s += %Q!\n<tr class="txtsql">!
    campos.each_index do |ind|
      cp = campos[ind]
      if (not sizes.blank?) && (not sizes[ind].blank?)
        s += %Q!\n <td>#{ text_field "txtsql", cp, :size => sizes[ind] 
}</td>!
      else
        s += %Q!\n <td>#{ text_field "txtsql", cp}</td>!
      end
    end
    s += %Q!\n <td>#{submit_tag "Ok", :title => "Buscar"} </td>!
    s += %Q!\n</tr>\n!

    registros.each do |registro|
      s += %Q!<tr class="#{ cycle('odd','par')}">!
      campos.each_index do |indice|
        cp = campos[indice]
        v = eval("registro."+cp)
        td = "\n<td>"
        txt = ""
        if color_txt_fld[indice]
          prcc = color_txt_fld[indice]
          txt += %Q!<font color="#{prcc.call(v, registro)}">!
        end if color_txt_fld
        if v.is_a?(String)
          txt += h(v)
        elsif cp =~ /folio/i        # Los folios no llevan punto de
separacion de miles
          td = %Q!\n<td align="right">!
          txt += v.to_s
        elsif cp =~ /pct/i
          td = %Q!\n<td align="right">!
          txt += number_to_currency(v*100.0, :unit => '%', :precision
=> 2, :delimiter => '')
        elsif v.is_a?(Float) || v.is_a?(BigDecimal)
          td = %Q!\n<td align="right">!
          txt += number_to_currency(v, :unit => '', :precision => 2,
:delimiter => '.')
        elsif v.is_a?(Fixnum) || v.is_a?(Bignum)
          td = %Q!\n<td align="right">!
          txt += number_to_currency(v, :unit => '', :precision => 0,
:delimiter => '.')   <---------------------------ACA SE CAE
        elsif v.is_a?(Date)
          txt += v.to_s(:my_date)
        elsif v.is_a?(ActiveSupport::TimeWithZone)
          txt += v.to_s(:my_time)
        elsif v.is_a?(FalseClass)
          txt += check_box_tag(cp, value = "0", checked = false,
options = {:disabled  => true})
        elsif v.is_a?(TrueClass)
          txt += check_box_tag(cp, value = "1", checked = true,
options = {:disabled => true})
        end
        txt += %Q!</font>! if color_txt_fld[indice]  if color_txt_fld
        s += td + txt + "</td>"
      end
      s += "\n <td>"

      s += link_to( image_tag('book_edit.png'),
edit_path.call(registro), :title => edit_title) if
edit_path.is_a?(Proc)

      if delete_path
        if delete_path.is_a?(String)
          s += link_to( image_tag('delete.png'), registro, :confirm =>
'¿ Esta ud seguro ?', :method => :delete, :title => delete_title)
        else
          s += link_to( image_tag('delete.png'),
delete_path.call(registro), :confirm => '¿ Esta ud seguro ?', :method
=> :delete, :title => delete_title)
        end
      end

      ad.each do |adic|
        s += link_to( image_tag(adic[:mono]),
adic[:path].call(registro), :title => adic[:titulo])
      end
      s += "</td>\n</tr>"
    end
    s += "\n</table>"
    s
  end


puede ser un problema en la base de datos?
deberas no se que paso.
Reinicie todo y nada.
Puse         <-----------------------ACA SE CAE donde falla

Y el log dice:

Rendering contmovimientos/index
  Contmovimiento Columns (0.0ms)   SHOW FIELDS FROM
`contmovimientos`
  Contrato Columns (16.0ms)   SHOW FIELDS FROM
`contratos`
  Contrato Load (0.0ms)   SELECT * FROM `contratos`
WHERE (`contratos`.`id` = 2) 
  Contratocomercio Columns (63.0ms)   SHOW FIELDS
FROM `contratocomercios`
  Contratocomercio Load (0.0ms)   SELECT * FROM
`contratocomercios` WHERE (`contratocomercios`.`id` = 130) 

ActionView::TemplateError (can't convert Fixnum into String) on line
#11 of app/views/contmovimientos/index.html.erb:
8:         (! @txtsql["contratocomercio.codigo_comercio"].blank?) ||
9:         (! @txtsql["fecha"].blank?) || (! @txtsql["trxs"].blank?) ||
10:         (! @txtsql["monto"].blank?) ||(@contmovimientos.size == 0))
11:     listado(@contmovimientos,
12:         {:cps => cps,
13:         :size => sz,
14:         :ttl => t(:contmovimiento, :count => @contmovimientos.size),

    app/helpers/application_helper.rb:91:in `+'
    app/helpers/application_helper.rb:91:in `listado'
    app/helpers/application_helper.rb:69:in `each_index'
    app/helpers/application_helper.rb:69:in `listado'
    app/helpers/application_helper.rb:67:in `each'
    app/helpers/application_helper.rb:67:in `listado'
    app/views/contmovimientos/index.html.erb:11
    app/controllers/contmovimientos_controller.rb:54:in `index'
    C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
    C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
    -e:1:in `load'
    -e:1

Rendered rescues/_trace (375.0ms)
Rendered rescues/_request_and_response (15.0ms)
Rendering rescues/layout (internal_server_error)

deberas no se que es, paso sin una razon aparente.
y dejo de funcionar en llamadas donde no cambie nada.
Ojala me den una pista.

Gracias
--
Angel Mauricio Pino G
AngelMauricio.PinoGonzalez@gmail.com
Movil: 08-577.92.72
Posted by Manuel González Noriega (Guest)
on 2009-07-01 09:45
(Received via mailing list)
2009/7/1 Angel Mauricio Pino Gonzalez 
<angelmauricio.pinogonzalez@gmail.com>

> Tengo un helper que crea mis index
> y de la nada dejo de funcionar, deshice los ultimos cambios pero aun
> asi no se arreglo.
> Alguna idea?
>


En cualquier caso, el mensaje de error parece bastante directo e 
inequívoco
¿Por qué no compruebas el tipado de esa variable y por qué es un fixnum 
en
vez de una string, etc.? Parece mejor para todos que dejar caer un 
asteroide
sobre la lista capaz de destruir continentes.

Como se ha dicho muchas veces, si vais a poner trozos no triviales de
código, usad http://pastie.org. Creo que es un poco demasiado pedir que 
la
gente se habra paso a traves de un código de ese tamaño sin formatear ni
colorear.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.