Rails is losing key information

I am using ruby 1.8.4 with rails 1.0 under fedora core 3 on a WIntel

Rails appears to be losing key information under some circumstances.

Specifically, in the Questions class that follows, the presentation_id
property is apparently being lost.

The STDOUT dump from the create method indicates that the
presentation_id should be 42, but the dump from the database shows that
it is 43, which is the same as the explanation_presentation_id

Any ideas? Is this a known bug that is fixed in a more recent version
of rails?

STDOUT dump:

Parent should be = 1
Parent = 1
Presentation is = dsfsasdafsa
Tip is = vcxzvzxc
Explanation is =
presentation_ID is = 42
explanation_presentation_id is = 43
tip_presentation_id is = 44

INSERT INTO QUESTIONS () VALUES (‘15’, ‘1’, ‘45’, ‘7’, ‘0’, NULL, ‘46’,

Results in database:

14 1 43

6 0 [null]

44 43

Firebird DDL:

create table presentations
ID INTEGER not null primary key,
textvalue varchar (1024),
audio varchar (1024),
visual varchar (1024)

create table quizzes
ID INTEGER not null primary key,
name varchar (255) not null,
preamble_presentation_id INTEGER references presentations(ID),
postamble_presentation_id INTEGER references presentations(ID)

create table questions
ID INTEGER not null primary key,
PARENT_ID INTEGER not null references quizzes(ID),
presentation_id INTEGER not null references presentations(ID),
seq integer not null,
points integer default 0 not null,
time_allowed integer,
tip_presentation_id INTEGER references presentations(ID),
explanation_presentation_id INTEGER references presentations(ID)
create unique ascending index quest_seq on questions (PARENT_ID,SEQ);

create generator presentations_seq;
create generator quizzes_seq;
create generator questions_seq;

Ruby model class:

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 :tip_presentation, :class_name =>
“Presentations”, :foreign_key => :presentation_id
belongs_to :explanation_presentation, :class_name =>
“Presentations”, :foreign_key => :presentation_id
belongs_to :parent, :class_name => “Quiz”
acts_as_list :scope => :parent_id, :column => :seq


Create method from question_controller.rb

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
@question.parent = Quiz.find(params[:parent_id].to_s, :limit => 1)

Fails because it is a HashWithIndifferentAccess, not a string

@question.parent = Quiz.find(params[:parent_id], :limit => 1)

@question.parent_id = @question.parent.id

@question.presentation = Presentations.new
@question.tip_presentation = Presentations.new
@question.explanation_presentation = Presentations.new

@question.presentation.textvalue = @params

@question.tip_presentation.textvalue = @params
@question.explanation_presentation.textvalue = @params

STDOUT.print(“Parent should be = “,params[:parent_id],”\r\n”)
STDOUT.print(“Parent = “,@question.parent.id,”\r\n”)
STDOUT.print(“Presentation is = “,@question.presentation.textvalue,”\r
STDOUT.print(“Tip is =
STDOUT.print(“Explanation is =

@question.presentation_id = @question.presentation.id

    @question.explanation_presentation_id =


    @question.tip_presentation_id = @question.tip_presentation.id

STDOUT.print(“presentation_ID is = “,@question.presentation.id,”\r\n”)
STDOUT.print(“explanation_presentation_id is =
STDOUT.print(“tip_presentation_id is =


to test rollback, throw an exception here


STDOUT.print(“Saved presentation and question successfully.\r\n”)
flash[:notice] = ‘Question was successfully created.’
redirect_to :action => ‘list’, :parent_id => params
[:parent_id], :question => params[:question]

STDOUT.print(“Failed to save presentations and question.\r\n”)
render :action => ‘new’

I just had a “doh!” moment. Never mind. My problem is in the class

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