# Listing user jobs

**URL:** <https://www.ruby-forum.com/t/listing-user-jobs/143684>\
**Category:** Rails\
**Created:** [July 21, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/listing-user-jobs/143684 "2008-07-21T20:25:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dc4da7/32.png) [@amrita](https://www.ruby-forum.com/u/amrita)\
**Post date:** [July 21, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/listing-user-jobs/143684/1 "2008-07-21T20:25:01Z")

</div>

Hi,

I am still on my first Rails application which consists of several  
models and their controllers and views. Recently, I added user  
authentication to the project and have been able to make it work so  
far. For all views, I have a common layout file “qalayout.html.erb”.  
This layout file contains the view logic for login/logout. It also  
allows user (if the user is logged in) to submit a new job to the site  
using a form in a div that is collapsible.

Now, I also want to include another collapsible div in which all jobs  
for that user are listed. I have a User model and a Job model. The Job  
model has a “user\_id” foreign key. So, far I have everything else  
working. Please note that these functionalities should be available to  
the user no matter what view they are at, if they are logged in, hence  
I have included the viewing logic in the common layout file.

What is the best way to go about listing the jobs? Should the  
controller method be defined in the ApplicationController as follows?

def userjobs  
@jobs = Job.find(:all, :conditions =\> { :user\_id =\>  
params[:userid] })  
end

How can I get all jobs to be listed from the qalayout.html.erb file?

Many thanks!

Amrita

---

<div class="post-metadata">

**Author:** ![amrita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dc4da7/32.png) [@amrita](https://www.ruby-forum.com/u/amrita)\
**Post date:** [July 21, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/listing-user-jobs/143684/2 "2008-07-21T22:56:24Z")

</div>

I have been able to list all jobs for a user with the following code:

In application\_helper.rb:

def userjobs  
userid = current\_user.id  
@jobs = Job.find(:all, :conditions =\> { :user\_id =\> userid })  
return(@jobs)  
end

In application.rb:

```
    helper :application

```

In qalayout.html.erb:

\<% if logged\_in? %\>  
View your  
jobs

 \<% @jobs = userjobs() %\> \<% for job in @jobs %\> \<%=h job.status %\> \<%=h job.filename %\> \<%=h job.created\_at %\> \<%=h job.updated\_at %\>   
 \<% end %\>

If you are reading this and this is not the best way to do this,  
please let me know.

Thanks,  
Amrita
