Topic: New to rails, trying to filter
So I am brand new to rails, and programming, and am trying to setup a filter that will have 2 options.
in my controller, I've got:
def index @expenses = Expense.filter(params[:category_id],[:who_id])
in my model I have
def self.filter(category_id, who_id) if category_id.present? or who_id.present? return Expense.where(:category_id => category_id, :who_id => who_id) else return Expense.all end end
and in my view I've got:
<% @expenses.each do |expense| %> <tr> <td><%= link_to expense.category.name, expenses_path(:category_id=>expense.category_id) %></td> <td><%= link_to expense.who.name, expenses_path(:who_id=>expense.who_id) %></td>
When I go to my index, there are no entries, and when I add an entry and go back to my index, the entry doesn't exist.