# Will not create new row in table

**URL:** <https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656>\
**Category:** Rails\
**Created:** [April 2, 2008, 11:06am UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656 "2008-04-02T11:06:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 11:06am UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/1 "2008-04-02T11:06:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 11:30am UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/2 "2008-04-02T11:30:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 2:21pm UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/3 "2008-04-02T14:21:38Z")

</div>

On 2 Apr 2008, at 10:06, Dag S. 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

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/4 "2008-04-02T14:24:38Z")

</div>

@presentation = current\_user.presentation  
@presentation ||= current\_user.create\_presentation

Looks much sexier, no?

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 3:09pm UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/5 "2008-04-02T15:09:23Z")

</div>

On 2 Apr 2008, at 14:06, Dag S. wrote:

> the  
> validations once?

You can set validations to run only on update (validates\_foo :on  
=\> :update)

Fred

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/6 "2008-04-02T15:06:12Z")

</div>

Frederick C. wrote:

> On 2 Apr 2008, at 10:06, Dag S. 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
```

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 3:28pm UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/7 "2008-04-02T15:28:37Z")

</div>

Frederick C. wrote:

> On 2 Apr 2008, at 14:06, Dag S. 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”

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 2, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/will-not-create-new-row-in-table/133656/8 "2008-04-02T15:46:27Z")

</div>

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”
