# Getting wrong id

**URL:** <https://www.ruby-forum.com/t/getting-wrong-id/226072>\
**Category:** Ruby\
**Created:** [July 29, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/getting-wrong-id/226072 "2010-07-29T15:44:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [July 29, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/getting-wrong-id/226072/1 "2010-07-29T15:44:55Z")

</div>

I have the follow method:

def concluir  
@subtarefa = Subtarefa.find(params[:id])  
@subtarefa.situacao\_subtarefa = “ConcluÃ­da”  
@subtarefa.data\_termino\_real = Date.current  
@subtarefa.update\_attributes(params[:subtarefa])

```
@subtarefas = Subtarefa.find(:all, :conditions =>

```

[“situacao\_subtarefa = ? AND tarefa\_id = ?”, “ConcluÃ­da”,  
@subtarefa.tarefa\_id])  
@tarefa = Tarefa.find(:first, :conditions =\> [“id = ?”,  
@subtarefa.tarefa\_id])  
num = (@tarefa.numero\_previsto\_subtarefas).to\_i  
if @subtarefas.size == num  
@tarefa.situacao\_tarefa = “ConcluÃ­da”  
@tarefa.data\_conclusao = Date.current  
@tarefa.update\_attributes(params[:tarefa])

```
@tarefas = Tarefa.find(:all, :conditions => ["situacao_tarefa = ?

```

AND projeto\_id = ?", “ConcluÃ­da”, @tarefa.projeto\_id])  
@projeto = Projeto.find(:first, :conditions =\> [“id = ?”,  
@tarefa.projeto\_id])  
num2 = (@projeto.numero\_previsto\_tarefas).to\_i  
if @tarefas.size == num2  
@projeto.situacao\_do\_projeto = “ConcluÃ­do”  
@projeto.data\_conclusao = Date.current  
@projeto.update\_attributes(params[:projeto])  
end  
end  
render :action =\> “show”  
flash[:msg] = “Subtarefa concluÃ­da com sucesso”  
end

My problem is:

undefined method `projeto’ for nil:NilClass

It gets the subtarefa’s id instead of tarefa’s id when i’m loking for a  
tarefa in Tarefa class.  
If it don’t get any tarefa with the subtarefa’s id (and it shouldn’t,  
'cause isn’t the right id), @tarefa will be a nil object, haven’t, that  
way, the “projeto\_id” method.

What am i missing?

---

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [July 29, 2010, 4:38pm UTC](https://www.ruby-forum.com/t/getting-wrong-id/226072/2 "2010-07-29T16:38:14Z")

</div>

actually, the problem is in here:

def verificai?  
@permissaoI = Permissao.all(:conditions =\> ["usuario\_id = ? AND  
perfil = ? AND (projeto\_id = ? OR projeto\_id = ? or projeto\_id = ?) ",  
session[:usuario\_id], “IntermediÃ¡rio”, Subtarefa.first(:conditions =\>  
[“id = ?”, params[:id]]).tarefa.projeto.id, Tarefa.first(:conditions =\>  
[“id = ?”, params[:id]]).projeto.id, params[:id]])  
if !@permissaoI.blank?  
return true  
else  
return false  
end  
end

---

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [July 30, 2010, 5:47pm UTC](https://www.ruby-forum.com/t/getting-wrong-id/226072/3 "2010-07-30T17:47:35Z")

</div>

when I get undefined method `projeto’ for nil:NilClass

it is almost always because I misspelled something or got the  
capitalization wrong  
if that helps
