Forum: Ruby on Rails Rails is losing key information

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
David J. (Guest)
on 2006-04-20 09:56
(Received via mailing list)
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.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.presentation =
    @question.tip_presentation =
    @question.explanation_presentation =

    @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           = ",,"\r\n")
STDOUT.print("Presentation is  = ",@question.presentation.textvalue,"\r
STDOUT.print("Tip is           =
STDOUT.print("Explanation is   =

        @question.presentation_id =!
        @question.explanation_presentation_id =!
        @question.tip_presentation_id =
STDOUT.print("presentation_ID is  = ",,"\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'
David J. (Guest)
on 2006-04-20 10:05
(Received via mailing list)
I just had a "doh!" moment. Never mind.  My problem is in the class
This topic is locked and can not be replied to.