# Job System user authentications problems

**URL:** <https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048>\
**Category:** Rails\
**Created:** [December 13, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048 "2007-12-13T17:07:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/1 "2007-12-13T17:07:19Z")

</div>

Hi All,

I have created sample job application which contain employers area,  
admin area and I am using Mysql database. I have created job post area  
or form via scaffold then I created authenticated area for employers  
via act\_as\_authenticated, now I have two users when they login they  
can see all posts and they can update or delete.

I want each user see his job posts, and by the way I have users table  
which created by act\_as\_authenticated and jobs tables I have created  
manually for job posts. I have added FK called users\_id in jobs table  
and it pointing to PK ID in users tables. When the employer fill new  
job post his ID not add to the database I don’t know why.

Could you please guide me to fix users authentications?

I am reading Agile Web D. with Rails book which good but it  
talk about shopping cart, I have not find what I need in other book,  
this is why I wrote my post here and looking for your help.

Yours,  
Waleed

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/2 "2007-12-13T18:00:26Z")

</div>

You will need to post the problem code.

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/3 "2007-12-13T18:06:17Z")

</div>

My post code I called employer as you see below :

class EmployerController \< ApplicationController  
before\_filter :login\_required

def index  
list  
render :action =\> ‘list’

end

# GETs should be safe (see

[URIs, Addressability, and the use of HTTP GET and POST](http://www.w3.org/2001/tag/doc/whenToUseGet.html))  
verify :method =\> :post, :only =\> [:destroy, :create, :update],  
:redirect\_to =\> { :action =\> :list }

def list

```
@job_pages, @jobs = paginate :jobs, :per_page => 10

```

end

def show  
@job = Job.find(params[:id])  
end

def new  
@job = Job.new  
end

def create  
@job = Job.new(params[:job])  
if @job.save  
flash[:notice] = ‘Job was successfully created.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

def edit  
@job = Job.find(params[:id])  
end

def update  
@job = Job.find(params[:id])  
if @job.update\_attributes(params[:job])  
flash[:notice] = ‘Job was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @job  
else  
render :action =\> ‘edit’  
end  
end

def destroy  
Job.find(params[:id]).destroy  
redirect\_to :action =\> ‘list’  
end  
end

This above code generated by scaffold and I have added  
before\_filter :login\_required.

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/4 "2007-12-13T21:06:39Z")

</div>

Could you please clarify it more?

1- I will add belongs\_to :employer to User model  
2- I do not have employer model and I have created it also I added  
has\_many :jobs, and has\_one :user  
3- I added belongs\_to :employer to Job model.

Still not work it show all list for all posts, by the way do I need  
create FK in my database? when I post new job i saw my FK null.

Any advices please ?

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/5 "2007-12-13T21:11:59Z")

</div>

The must be user\_id not users\_id. That could be the problem. Look at  
the output in the dev log.

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 8:11pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/6 "2007-12-13T20:11:08Z")

</div>

You need to make some new files.

A User model (which I think you already have) which  
belongs\_to :employer  
An Employer model which has\_many :jobs, and has\_one :user  
A Job Model which belongs\_to :employer

The code you listed shows all your Job activies in your employer  
controller.  
Get all your controller code generated. I have the feeling you got a  
little mixed up.

thanks,  
C.

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 14, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/7 "2007-12-14T16:19:39Z")

</div>

If you are seeing all jobs for all posts you are making progress.

If your Employer model has\_many :jobs than you can do something like

@first\_employer = Employer.find(:first)

than in a view you can do

\<% @first\_employer.jobs.each do |job| %\>  
\<%= job.id %\>   
  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![Waleed\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a88e57/32.png) [@Waleed\_H](https://www.ruby-forum.com/u/Waleed_H)\
**Post date:** [December 13, 2007, 9:15pm UTC](https://www.ruby-forum.com/t/job-system-user-authentications-problems/123048/8 "2007-12-13T21:15:31Z")

</div>

It is user\_id
