Okay, what gives? find_by_id is failing


#1

This has the look of a “just don’t quite get it yet” problem. I am
using the ActiveRecord.find_by_id method to identify the parent object
(Quiz) to tie to the child object (Question) at create time.

Here is the stdout log:

127.0.0.1 - - [31/Mar/2006:22:43:22 CST] “GET /question/new?
parent_quiz=ff2d7022-be0a-11da-9f01-00400506faf5 HTTP/1.1” 200 806
http://localhost:3000/questions?parent_quiz=ff2d7022-
be0a-11da-9f01-00400506faf5 -> /question/new?parent_quiz=ff2d7022-
be0a-11da-9f01-00400506faf5


Parent = nil


Parent should be = ff2d7022-be0a-11da-9f01-00400506faf5

127.0.0.1 - - [31/Mar/2006:22:43:23 CST] “POST /question/create
HTTP/1.1” 500 7042
http://localhost:3000/question/new?parent_quiz=ff2d7022-
be0a-11da-9f01-00400506faf5 -> /question/create

Here is the code for question:

class Question < ActiveRecord::Base
require ‘presentations’
require ‘question’

include UUIDHelper

has_many :answers, :order => :seq
belongs_to :presentation, :class_name => “Presentations”, :foreign_key
=> :presentation_id
belongs_to :parent, :class_name => “Quiz”
acts_as_list :scope => :parent_id, :column => :seq

end

Here is the code for question_controller:

def create

changed because we are instantiating the presentations here

may not be needed if we instantiate presentations in the initialize,

but that will require thinking because we already have a use for

the initialize method.

@question = Question.new
aParent = Quiz.find_by_id(params[:parent_quiz])

STDOUT.print("\r\n------------------------------\r\n")
STDOUT.print(“Parent = “,aParent,”\r\n”)
@question.parent = aParent

@question.presentation = Presentations.new
@question.presentation.textvalue = @params

[:question][:presentation][:textvalue]

STDOUT.print("\r\n------------------------------\r\n")
STDOUT.print(“Parent should be = “,params[:parent_quiz],”\r\n”)

– *** Blows up here ***
STDOUT.print(“Parent = “,@question.parent.id.to_str,”\r\n”)

if @question.presentation.save && @question.save
  flash[:notice] = 'Question was successfully created.'
  redirect_to :action => 'list', :parent_quiz => params

[:parent_quiz], :question => params[:question]
else
render :action => ‘new’
end
end