El Tue, 24 de May de 2011, a las 05:36:21PM -0300, Paolo Loran dijo:
> Buenas tardes, pido perdón de antemano por si cometo errores tontos, es que
> soy bastante nuevo en esto.
> El tema es asi, tengo el siguiente metodo:
> 
> ______________________________________________
> def current_degree
>     current_date = degree_changes.find(:first, :select => 'max(date) as
> max').max
>     change = degree_changes.where(:date => current_date).first
>     change.degree

      change vale Nil acá, ese es el problema, la forma rápida y sucia de
      solucionarlo es así:

      return "" if change.nil?
      change.degree

>   end
> __________________________________________



> y en la vista quiero mostrarlo:
> .....
> <% @students.each do |student| %>
>   <tr>
>     <td><%= student.surname %></td>
>     <td><%= student.name %></td>
>     <td><%= student.current_degree %></td>
>     .........
> __________________________________________
> Pero me da el siguiente error:
> 
> undefined method `degree' for nil:NilClass
> 
> Extracted source (around line *#25*):
> 
> 22:   <tr>
> 23:     <td><%= student.surname %></td>
> 24:   <td><%= student.name %></td>
> 25:   <td><%= student.current_degree %></td>
> 26:     <td><%= student.birthday %></td>
> 27:     <td><%= student.dni %></td>
> 28:   <td><%= student.phone_number %></td>
> _____________________________________________________
> Tengo las clases relacionadas con has_many y belongs_to
> tambien lo probe mediante una consola(rails c)
> 
> que podra ser?
> 
> salud!!!
> poli

> _______________________________________________
> Ruby mailing list
> [email protected]
> http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar


-- 
"Optimism is an occupational hazard of programming; feedback is the treatment."

(Kent Beck)


+-------------------------------------+
Gastón Ramos
http://gastonramos.com.ar/
GNU/Linux Counter user #450312
_______________________________________________
Ruby mailing list
[email protected]
http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar

Responder a