# Trying to Replicate a Login Generator related Tutorial

**URL:** <https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670>\
**Category:** Rails\
**Created:** [November 12, 2006, 4:43am UTC](https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670 "2006-11-12T04:43:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f19dbf/32.png) [@bernie](https://www.ruby-forum.com/u/bernie)\
**Post date:** [November 12, 2006, 4:43am UTC](https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670/1 "2006-11-12T04:43:13Z")

</div>

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

[http://d-haven.org/modules/news/article.php?storyid=28](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

---

<div class="post-metadata">

**Author:** ![bernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f19dbf/32.png) [@bernie](https://www.ruby-forum.com/u/bernie)\
**Post date:** [November 12, 2006, 5:09am UTC](https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670/2 "2006-11-12T05:09:07Z")

</div>

Bernie wrote:

> I am trying to replicate the “demo/tutorial” at
> 
> [http://d-haven.org/modules/news/article.php?storyid=28](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.

---

<div class="post-metadata">

**Author:** ![bernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f19dbf/32.png) [@bernie](https://www.ruby-forum.com/u/bernie)\
**Post date:** [November 12, 2006, 6:09am UTC](https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670/3 "2006-11-12T06:09:19Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![bernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f19dbf/32.png) [@bernie](https://www.ruby-forum.com/u/bernie)\
**Post date:** [November 13, 2006, 1:59am UTC](https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670/4 "2006-11-13T01:59:41Z")

</div>

I have a user\_id field in the Articles table.

On Nov 11, 10:09 pm, Cayce B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![bernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f19dbf/32.png) [@bernie](https://www.ruby-forum.com/u/bernie)\
**Post date:** [November 13, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/trying-to-replicate-a-login-generator-related-tutorial/75670/5 "2006-11-13T18:19:20Z")

</div>

Bernie wrote:

> I have a user\_id field in the Articles table.
> 
> On Nov 11, 10:09 pm, Cayce B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

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]
