I currently use .find_by_status(params[:status]) on my @tasks to find tasks that aren't closed or a sticky. (either 4,5).
def self.find_by_status(status)
status = status.to_i
if status == 0 then
status = 1
else
status = status
end
if status == 1 || !status then
Task.where(["STATUS NOT IN (4,5)"])
else
Task.where(:status => status)
end
end
I also copied this for my tickets model too, to find only open tickets on the home page.
It's also accompanied by this
<% status_active = 1 %>
<% Task.new.statuses.each do |status| %>
<li class="<%= if (params[:status].to_i || status_active) == status[0] then "active" end %>">
<%= link_to status[1], :controller => params[:controller], :action => params[:action], :params => { :status => status[0] } %>
</li>
I'm new to rails and I'm really struggling on refactoring this. I would probably prefer making those links into a drop down select filter, but that also I struggle with.
Any help is appreciated!