Getting wrong id

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?

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs