Dag Stensson
2008-Mar-06 13:16 UTC
Creating a default, empty row in Table with user_id fails
Hi, I''m stuck with something quite easy. I''ve done this before
to create
an empty row in a table connected to a current_user...and that looks
like this (placed in the user_controller''s create method):
# Creating a default, empty row in Presentations Table
@presentation = current_user.presentation
@presentation = current_user.create_presentation unless @presentation
# Creating a default, empty row in Entries Table
@entry = current_user.entry
@entry = current_user.create_entry unless @entry
Then I added a third table called Specs and wanted to create the same
thing.
@spec = current_user.spec
@spec = current_user.create_spec unless @spec
But it refuses to create an empty row in the table connected to a
user_id...
Can''t understand why...
Models involved are: User.rb & Spec.rb
###################################################
class User < ActiveRecord::Base #class definition
has_one :spec
has_one :presentation
has_one :entry
###################################################
class Spec < ActiveRecord::Base
belongs_to :user
###################################################
(the specs table works as long as I manually insert the user_id and
whitespace)
###################################################
create_table "specs", :force => true do |t|
t.column "user_id", :integer
t.column "first_name", :string
t.column "last_name", :string
t.column "gender", :string
t.column "occupation", :string
t.column "brithdate", :datetime
t.column "city", :string
t.column "country", :string
t.column "zip_code", :string
####################################################
please, this such a stupid error...anyone provide me with a solution
...I''m going blind by my own code
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---