will not create new row in table

Hi,

I've successfully used:

@presentation = current_user.presentation @presentation = current_user.create_presentation unless @presentation

before in my code when creating a new user (in the users_controller) to create an "empty" presentation table.

This does not work when I copy the above code and replace "presentation" with "spec", even though there should be no other differances for implementing it.

The Specs db-table is built in the same way, containing the same properties for default, not null?, unsigned?, Zerofil?. All which are empty.

My relations are right (as far as I can see) User.rb "has_one :spec" Spec.rb "belongs_to :user"

This is such a stupid error, forcing me to manually fill the Specs table to get it to work.

What can be wrong?

eMy Log shows that it refuses to use INSERT INTO in spec.

presentation: e[4;35;1mPresentation Columns (0.000000)e[0m e[0mSHOW FIELDS FROM presentationse[0m   e[4;36;1mSQL (0.000000)e[0m e[0;1mBEGINe[0m   e[4;35;1mSQL (0.000000)e[0m e[0mINSERT INTO presentations (`user_id`, `pres`) VALUES(11, NULL)e[0m   e[4;36;1mSQL (0.031000)e[0m e[0;1mCOMMITe[0m

spec: e[4;36;1mSpec Load (0.000000)e[0m e[0;1mSELECT * FROM specs WHERE (specs.user_id = 11) LIMIT 1e[0m   e[4;35;1mSpec Columns (0.016000)e[0m e[0mSHOW FIELDS FROM specse[0m   e[4;36;1mSQL (0.000000)e[0m e[0;1mBEGINe[0m   e[4;35;1mSQL (0.000000)e[0m e[0mCOMMITe[0m

Hi,

I've successfully used:

@presentation = current_user.presentation @presentation = current_user.create_presentation unless @presentation

before in my code when creating a new user (in the users_controller)
to create an "empty" presentation table.

This does not work when I copy the above code and replace
"presentation" with "spec", even though there should be no other differances for implementing it.

Could there be validations on spec that are failing ?

Fred

@presentation = current_user.presentation @presentation ||= current_user.create_presentation

Looks much sexier, no?

Frederick Cheung wrote:

create an "empty" presentation table.

This does not work when I copy the above code and replace
"presentation" with "spec", even though there should be no other differances for implementing it.

Could there be validations on spec that are failing ?

Fred

Yeah, Thanks Fred! You were absolutely right! I had a few validations failing since the rows are empty. ;D

Removing the validations solves it, but I want to use the validations later on when I update...So I kept them, is there any way to bypass the validations once?

I tried this but that didn't solve it.

    @spec = Spec.new     @spec.save(false)     @user.spec = @spec     @user.save

Could there be validations on spec that are failing ?

Fred

Yeah, Thanks Fred! You were absolutely right! I had a few validations failing since the rows are empty. ;D

Removing the validations solves it, but I want to use the validations later on when I update...So I kept them, is there any way to bypass
the validations once?

You can set validations to run only on update (validates_foo :on
=> :update)

Fred

Frederick Cheung wrote:

the validations once?

You can set validations to run only on update (validates_foo :on => :update)

Fred

If you meant like this it doesn't work, otherwise I'd appriciate if you'd be more exact (I'm sort of a newbee still)

[...in spec.rb...] validates_format_of :zip_code, :with => /(^$|^[0-9]{#{ZIP_CODE_LENGTH}}$)/,                       :on => :update,                       :message => "must be a five digit number"

I've narrowed it down to ONE validation which doesn't work

validates_inclusion_of :gender, :on => :update,                        :in => VALID_GENDERS,                        :allow_nil => true,                        :message => "must be male or female"