Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting wrong id

0 views
Skip to first unread message

Bla ...

unread,
Jul 29, 2010, 9:44:57 AM7/29/10
to
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?
--
Posted via http://www.ruby-forum.com/.

BruceL

unread,
Jul 30, 2010, 11:20:45 AM7/30/10
to
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

0 new messages