Trying to Replicate a Login Generator related Tutorial

I am trying to replicate the “demo/tutorial” at

http://d-haven.org/modules/news/article.php?storyid=28

I have ran the generator and followed the instructions in the
accompanying generator readme_login file.

I have setup up a user database of the form

create_table :users do |t|
t.column :login, :string, :limit => 40
t.column :password, :string, :limit => 40
t.column :email, :string, :limit => 40
t.column :name, :string, :limit => 40

and from there followed the procedures listed at the site noted above
thru the end of Step 2 including creating another table (articles table
referred to in demo) with a user_id :interger column.

After creating a user I attempt to create and save an article
instance/record which fails at the

validates_presence_of :user

Can you see anything in the “demo/tutorial” code which is out of place
or have I missed some step required to get the session :user properly
assigned to the @article instance?

Thanks,
Bernie

Bernie wrote:

I am trying to replicate the “demo/tutorial” at

http://d-haven.org/modules/news/article.php?storyid=28

I have ran the generator and followed the instructions in the
accompanying generator readme_login file.

I have setup up a user database of the form

create_table :users do |t|
t.column :login, :string, :limit => 40
t.column :password, :string, :limit => 40
t.column :email, :string, :limit => 40
t.column :name, :string, :limit => 40

and from there followed the procedures listed at the site noted above
thru the end of Step 2 including creating another table (articles table
referred to in demo) with a user_id :interger column.

After creating a user I attempt to create and save an article
instance/record which fails at the

validates_presence_of :user

Can you see anything in the “demo/tutorial” code which is out of place
or have I missed some step required to get the session :user properly
assigned to the @article instance?

Thanks,
Bernie

Do you have a ‘user’ field on your Articles table?

I only skimmed the start of the post, but my first thought is that the
articles table should have a ‘user_id’ field, not a ‘user’ field, to
link Articles to Users through the has_many/belongs_to associations, and
then the line should be:

validates_presence_of :user_id

c.

The field in the articles table is user_id.

Also in the tutorial articles_controller there are references to
@article.user and @session[:user]. Should these not be .user_id as
well? (pardon my noobiness)

On Nov 11, 10:09 pm, Cayce B. [email protected]

I have a user_id field in the Articles table.

On Nov 11, 10:09 pm, Cayce B. [email protected]

Bernie wrote:

I have a user_id field in the Articles table.

On Nov 11, 10:09 pm, Cayce B. [email protected]

Have a look to the session[:user] and so on, I think Login-generator
puts the values with ‘’ (e.g. session[‘user’]), and you articles or some
other stuff may be asking for session[:user]

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