Rails enums

Associate
Joined
19 Jul 2006
Posts
1,847
Is there a better way of doing this.
I have a Job model
Code:
class Job < ActiveRecord::Base
enum category: [:Full_time, :Part_time, :Freelance]
end

Job Controller
Code:
class JobsController <ApplicationController

...

def index
   if params[:category].blank?
      @jobs = Job.all
   else
       @jobs = Job.where(category: params[:category])
 end
end
...

and then I have a _nav partial.haml
Code:
- Job.categories.each do |c|

   = link_to c[0].humanize , jobs(category: c[1])

This works it displays the links as the word eg Part Time and then the param is sent of 1 which then displays all the jobs.

It just feels a bit messy to me in the nav partial that I am using it as an array. Is there a better/cleaner way of doing this
 
Back
Top Bottom