Problems with Find

Hola, estoy aprendiendo Ruby y tengo un problema… y al parecer la
informacion que hay al respecto no la he entendido, por lo que
agradeceré ayuda…

Estoy llamando a un metodo, dentro de este necesito cargar @trabajador,
lo hago de la siguiente manera:

@trabajador = Trabajador.find(:all,
:conditions =>[" persona_id = "+ params[:id]])

el id, viene del .rhtml que carga el método.
El error que me aparece es:

undefined method `stringify_keys!’ for “240”:String

entiendo que me está tomando el id correctamente pero que lo lee como un
string en vez de un integer… como diablos le digo que es un
integer?!?!?!

gracias…


HI I’m learning Ruby anda have a problem, and it seems that i can’t
understand the information abaout it, so i’ll thank your help.

i’m calling a method, inside it i need to load @trabajador:

@trabajador = Trabajador.find(:all,
:conditions =>[" persona_id = "+ params[:id]])

the id, comes from a .rhtml that calls the method, the error I get is:

undefined method `stringify_keys!’ for “240”:String

I think it’s telling me that it was expecting a integer and i send it a
string… how do i tell it to make id an integer???

thanks

I think you need to change…

@trabajador = Trabajador.find(:all, :conditions => [" persona_id = "+
params[:id]])

to…

@trabajador = Trabajador.find(:all, :conditions => [" persona_id = ?",
params[:id]])

Camila wrote:

Hola, estoy aprendiendo Ruby y tengo un problema… y al parecer la
informacion que hay al respecto no la he entendido, por lo que
agradeceré ayuda…

Estoy llamando a un metodo, dentro de este necesito cargar @trabajador,
lo hago de la siguiente manera:

@trabajador = Trabajador.find(:all,
:conditions =>[" persona_id = "+ params[:id]])

el id, viene del .rhtml que carga el método.
El error que me aparece es:

undefined method `stringify_keys!’ for “240”:String

entiendo que me está tomando el id correctamente pero que lo lee como un
string en vez de un integer… como diablos le digo que es un
integer?!?!?!

gracias…


HI I’m learning Ruby anda have a problem, and it seems that i can’t
understand the information abaout it, so i’ll thank your help.

i’m calling a method, inside it i need to load @trabajador:

@trabajador = Trabajador.find(:all,
:conditions =>[" persona_id = "+ params[:id]])

the id, comes from a .rhtml that calls the method, the error I get is:

undefined method `stringify_keys!’ for “240”:String

I think it’s telling me that it was expecting a integer and i send it a
string… how do i tell it to make id an integer???

thanks

Hola Camila. Lo que veo es que tu condicion no esta bien.

Trata con:

@trabajador = Trabajador.find(:all,
:conditions =>[“persona_id = ?”, params[:id]])

Espero que te ayude.

Seems like I’m late :slight_smile:

Me podrias mostrar el view de donde haces el post?

Thanks, I was really happy to finally have some answers… but it
didn’t work!!! I sware…
It keeps giving me the same error.
undefined method `stringify_keys!’ for “240”:String
any other idea?? please!!!


Gracias, estaba super contenta de tener algunas respuestas… pero no
funcionó!!! lo juro…

Me sigue dando el mismo error.
undefined method `stringify_keys!’ for “240”:String

alguna otra idea? porfa!!

I don’t think that line of code is what’s causing the problem. It would
help if you could show us more of your code - the whole controller
method, the whole view and the stack trace.

If there’s too much code, then you should try deleting some code - keep
deleting code until the problem goes away, then show us the smallest
amount of code that still causes the problem.

I think this line is the problem:

if @persona.update_attributes(params[:id])

It looks like you’re passing a String (the id) to the method, but it
wants a hash of attribute => value pairs.

ok, here goes the view file:
<%= start_form_tag (:action=> ‘update’, :id=> @persona) %>

Detalles <%=h @persona.nombre %> <%=h @persona.apellido1 %></h3

      </tr>
                <tr>
                  <td><strong>Correo electr&oacute;nico: 

      </tr>
      <tr>
                  <td><strong>Direcci&oacute;n Postal: 









                          <% if @persona.estudios != nil%>
                                <% @persona.estudios.each do |e|%>
                                <tr>
                                    <td>
                                        <%= link_to 'Eliminar 

Estudio’, :action => ‘eliminar’, :id => @persona %>





<%end%>
<%end%>
            <tr>
      <td><strong>Empresas:</strong></td>
                          <td colspan="3">
        </tr>

                          <% if @persona.trabajadores != nil%>
                                <% @persona.trabajadores.each do 

|t|%>





<%if t.secre != nil%>

<%else%>

<%end%>

<%end%>
<%end%>

<div id = agregar_empresa
      </tr>
      <tr>
        <td><strong>Direcci&oacute;n Trabajo:</strong></td>
        <td>
                    <%= text_field ('persona',"calle_trabajo") %>
                  </td>
                  <td>
                    <%= text_field ('persona',"numero_trabajo") %>
                  </td>
                  <td>
                     <%= text_field('persona',"ciudad_trabajo") %>
                  </td>
                  <td>
                  <%= select 'persona', 

‘pais_trabajo’,Parametros.paises %>









<%else%>
<%= check_box(“mapla”, “login”, {}, “1”,
“0”)%>
<%end%>



<%if @persona.sin_rut = “true” or
@persona.mail_rebotado = “true” or @persona.telefono_malo = “true” or
@persona.gest_eventos = “true”%>

<%end%>
                       </tr>
      <tr>
                   <td><strong>Observaciones:</strong></td>
          <td colspan="3">
         <%= text_area('persona',"observaciones") %>
          </td>
                   </tr>
                <tr>
        <td><%= link_to 'Enviar Mail', :action => 'escribir_mail' , 

:id => @persona %>










Nombre Completo:

 

<%= text_field ('persona','nombre') %> <%= text_field ('persona',"apellido1") %> <%= text_field ('persona',"apellido2") %>
RUT/Pasaporte: <%= text_field('persona',"rut") %> Fecha de Nacimiento: <%= date_select("persona", "fecha_de_nacimiento")%>
Nacionalidad: <%= text_field ('persona',"nacionalidad") %> Idiomas: <% if @persona.idiomas != nil %> <% @persona.idiomas.each do |i|%> <%= i.idioma%> <%= check_box("idiomas", "idioma", {:checked => "checked"}, "1", "0")%> <% end%> <% end%> <%= select_tag 'idiomas[]', options_for_select(Idioma.list_idiomas),{:size =>3} %>
<%= text_field (‘persona’,“calle”) %>

<%= text_field (‘persona’,“numero”) %>

<%= text_field (‘persona’,“ciudad”) %>

<%= select ‘persona’, ‘pais’,Parametros.paises %>
Estudios:
Grado:
<%= e.grado%>
Institucion:
<%= e.institucion %>
Año:
<%= e.ano.year
%>

<%= link_to ‘Agregar Estudios’,
:action => ‘agregar_estudios’, :id => @persona %>
Grado: <%= text_field ('estudio',"grado") %> Institución: <%= text_field ('estudio',"institucion") %> Año: <%= date_select 'estudio', 'ano', :start_year => 1940, :discard_day => true,:discard_month => true %>

<%= link_to ‘Borrar de
Empresa’, :action => ‘borrar’, :persona_id => @persona, :empresa_id
=>t.empresa.id %>

Empresa:
<%= t.empresa.razon_social%>
Cargo:
<%= text_field
(‘trabajadores’,‘cargo’) %>
Secretaria:
<%=
t.secre.nombre%>
<%=
t.secre.apellido1%>
<%=
t.secre.apellido2%>
<%=
t.secre.telefono%>
<%= link_to
‘Desvincular Secretaria’, :action => ‘desvincular’, :id => @persona %>
<%= link_to
‘Vincular Secretaria’, :action => ‘vincular’, :id => @persona %>

<%= link_to ‘Agregar a Empresa’,
:action => ‘agregar_empresa’, :id => @persona %>
Empresa: <%= select_tag 'empresas[]', options_for_select(@empresas),{ :multiple => true, :size => 5 } %> Cargo: <%= text_field ('trabajadores',"cargo") %> <%= link_to 'Vincular Secretaria', :action => 'vincular', :id => @persona %>
Área
Interes:

<% if @persona.areas != nil%>
<% @persona.areas.each do |i|%>
<% if i.tipo == “I” %>
<%= i.nombre_area%>
<%= check_box(“area”, “nombre_area”,
{:checked => “checked”}, “1”, “0”)%>
<%end%>
<%end%>
<%end%>
<%= select_tag ‘areas[]’,
options_for_select(@list_areas_interes),{
:multiple => true, :size => 5 }
%>
Área Especialización:

<% if @persona.areas != nil%>
<% @persona.areas.each do |i|%>
<% if i.tipo == “E” %>
<%= i.nombre_area%>
<%= check_box(“area”, “nombre_area”,
{:checked => “checked”}, “1”, “0”)%>
<%end%>
<%end%>
<%end%>
<%= select_tag ‘areas[]’,
options_for_select(@list_areas_especializacion),{
:multiple => true, :size => 5 }
%>
      </tr>
      <tr>
           <td><strong>Pertenece a Mapla
             <%if @persona.login_mapla != nil %>
                 <%= check_box("mapla", "login", {:checked => 

“checked”}, “1”, “0”)%>
<div id = pertenece_mapla


Nombre de
Usuario:

<%= text_field
(‘persona’,“login_mapla”) %>
Password:

<%= text_field
(‘persona’,“password_mapla”) %>
Origen de la
Información:

<%= text_field (‘persona’,“origen_dato”) %>

Falta Revisión
<%= check_box (‘en_seguimiento’, ‘revision’,
{:checked => ‘checked’},“1”, “0” )%>
Eliminar <%= submit_tag “Guardar”%>

<%= end_form_tag %>
<%= link_to ‘Atras’, :action => ‘list’ %>

The submit_tag Guardar calls the following controller method:

def update # Metodo utilizado para guardar cambios de personas.
(Editar) Camila Bolaños 5/1/07
@persona = Persona.find(params[:id])
@idioma = Idioma.find_all
@trabajador = Trabajador.find(:all, :conditions => [" persona_id =
?",params[:id]])

if @persona.update_attributes(params[:id])

       flash[:notice] = 'El contacto ha sido modificado 

exitosamente’
redirect_to :action => ‘list’, :id => @persona
else
flash[:notice] = ‘El contacto NO ha sido modificado, revise la
información’
redirect_to :action => ‘show’, :id=> @persona
end
end

The error:
undefined method `stringify_keys!’ for “106”:String

… Thanks for helping…

try this:

@trabajador = Trabajador.find(:all, :conditions =>[“persona_id = ?”,
params[:id]])

HTH

Snow Man wrote:

I think this line is the problem:

if @persona.update_attributes(params[:id])

It looks like you’re passing a String (the id) to the method, but it
wants a hash of attribute => value pairs.

Thanks Snow Man… I change it to

if @persona.update_attributes(params[:persona])

and it works!!! I’m really glad.
Of course I’ll have some other problems with ruby so we’ll be in
touch…

Chika