Listing user jobs


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] })

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

Many thanks!


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

In application_helper.rb:

def userjobs
userid =
@jobs = Job.find(:all, :conditions => { :user_id => userid })

In application.rb:

    helper :application

In qalayout.html.erb:

<% if logged_in? %>
View your

<% @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.